This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2022-03-08 23:52:32 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::InstanceAccountsDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-05 07:52:33 -07:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
2022-03-08 23:52:32 -08:00
|
|
|
include LanguagesHelper
|
|
|
|
|
|
|
|
def self.with_params?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
'instance_accounts'
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-05 07:52:33 -07: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-08 23:52:32 -08:00
|
|
|
SELECT accounts.username, count(follows.*) AS value
|
|
|
|
FROM accounts
|
|
|
|
LEFT JOIN follows ON follows.target_account_id = accounts.id
|
2023-06-05 07:52:33 -07:00
|
|
|
WHERE accounts.domain = :domain
|
2022-03-08 23:52:32 -08:00
|
|
|
GROUP BY accounts.id, follows.target_account_id
|
|
|
|
ORDER BY value DESC
|
2023-06-05 07:52:33 -07:00
|
|
|
LIMIT :limit
|
2022-03-08 23:52:32 -08:00
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def params
|
|
|
|
@params.permit(:domain)
|
|
|
|
end
|
|
|
|
end
|