2022-03-09 01:52:32 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::InstanceAccountsDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-05 09:52:33 -05:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
2022-03-09 01:52:32 -06:00
|
|
|
include LanguagesHelper
|
|
|
|
|
|
|
|
def self.with_params?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
'instance_accounts'
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-05 09:52:33 -05:00
|
|
|
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
|
2022-03-09 01:52:32 -06:00
|
|
|
SELECT accounts.username, count(follows.*) AS value
|
|
|
|
FROM accounts
|
|
|
|
LEFT JOIN follows ON follows.target_account_id = accounts.id
|
2023-06-05 09:52:33 -05:00
|
|
|
WHERE accounts.domain = :domain
|
2022-03-09 01:52:32 -06:00
|
|
|
GROUP BY accounts.id, follows.target_account_id
|
|
|
|
ORDER BY value DESC
|
2023-06-05 09:52:33 -05:00
|
|
|
LIMIT :limit
|
2022-03-09 01:52:32 -06:00
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def params
|
|
|
|
@params.permit(:domain)
|
|
|
|
end
|
|
|
|
end
|