Rails 7 compatibility fix for Admin::Metrics::Dimension
classes (#25277)
This commit is contained in:
parent
70cd2d6000
commit
3b21c13dcc
17 changed files with 297 additions and 44 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::InstanceAccountsDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
include Admin::Metrics::Dimension::QueryHelper
|
||||
include LanguagesHelper
|
||||
|
||||
def self.with_params?
|
||||
|
@ -14,19 +15,23 @@ class Admin::Metrics::Dimension::InstanceAccountsDimension < Admin::Metrics::Dim
|
|||
protected
|
||||
|
||||
def perform_query
|
||||
sql = <<-SQL.squish
|
||||
dimension_data_rows.map { |row| { key: row['username'], human_key: row['username'], value: row['value'].to_s } }
|
||||
end
|
||||
|
||||
def sql_array
|
||||
[sql_query_string, { domain: params[:domain], limit: @limit }]
|
||||
end
|
||||
|
||||
def sql_query_string
|
||||
<<~SQL.squish
|
||||
SELECT accounts.username, count(follows.*) AS value
|
||||
FROM accounts
|
||||
LEFT JOIN follows ON follows.target_account_id = accounts.id
|
||||
WHERE accounts.domain = $1
|
||||
WHERE accounts.domain = :domain
|
||||
GROUP BY accounts.id, follows.target_account_id
|
||||
ORDER BY value DESC
|
||||
LIMIT $2
|
||||
LIMIT :limit
|
||||
SQL
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:domain]], [nil, @limit]])
|
||||
|
||||
rows.map { |row| { key: row['username'], human_key: row['username'], value: row['value'].to_s } }
|
||||
end
|
||||
|
||||
def params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue