2022-03-09 18:52:32 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Dimension::BaseDimension
|
2023-06-06 00:52:33 +10:00
|
|
|
include Admin::Metrics::Dimension::QueryHelper
|
2022-03-09 18:52:32 +11:00
|
|
|
include LanguagesHelper
|
|
|
|
|
|
|
|
def self.with_params?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
'instance_languages'
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_query
|
2023-06-06 00:52:33 +10:00
|
|
|
dimension_data_rows.map { |row| { key: row['language'], human_key: standard_locale_name(row['language']), value: row['value'].to_s } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_array
|
|
|
|
[sql_query_string, { domain: params[:domain], earliest_status_id: earliest_status_id, latest_status_id: latest_status_id, limit: @limit }]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_query_string
|
|
|
|
<<~SQL.squish
|
2022-03-09 18:52:32 +11:00
|
|
|
SELECT COALESCE(statuses.language, 'und') AS language, count(*) AS value
|
|
|
|
FROM statuses
|
|
|
|
INNER JOIN accounts ON accounts.id = statuses.account_id
|
2023-06-06 00:52:33 +10:00
|
|
|
WHERE accounts.domain = :domain
|
|
|
|
AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
2022-03-09 18:52:32 +11:00
|
|
|
AND statuses.reblog_of_id IS NULL
|
|
|
|
GROUP BY COALESCE(statuses.language, 'und')
|
|
|
|
ORDER BY count(*) DESC
|
2023-06-06 00:52:33 +10:00
|
|
|
LIMIT :limit
|
2022-03-09 18:52:32 +11:00
|
|
|
SQL
|
2023-06-06 00:52:33 +10:00
|
|
|
end
|
2022-03-09 18:52:32 +11:00
|
|
|
|
2023-06-06 00:52:33 +10:00
|
|
|
def earliest_status_id
|
|
|
|
Mastodon::Snowflake.id_at(@start_at, with_random: false)
|
|
|
|
end
|
2022-03-09 18:52:32 +11:00
|
|
|
|
2023-06-06 00:52:33 +10:00
|
|
|
def latest_status_id
|
|
|
|
Mastodon::Snowflake.id_at(@end_at, with_random: false)
|
2022-03-09 18:52:32 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def params
|
|
|
|
@params.permit(:domain)
|
|
|
|
end
|
|
|
|
end
|