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