instance_languages_dimension.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Dimension::BaseDimension
  3. include Admin::Metrics::Dimension::QueryHelper
  4. include LanguagesHelper
  5. def self.with_params?
  6. true
  7. end
  8. def key
  9. 'instance_languages'
  10. end
  11. protected
  12. def perform_query
  13. dimension_data_rows.map { |row| { key: row['language'], human_key: standard_locale_name(row['language']), value: row['value'].to_s } }
  14. end
  15. def sql_array
  16. [sql_query_string, { domain: params[:domain], earliest_status_id: earliest_status_id, latest_status_id: latest_status_id, limit: @limit }]
  17. end
  18. def sql_query_string
  19. <<~SQL.squish
  20. SELECT COALESCE(statuses.language, 'und') AS language, count(*) AS value
  21. FROM statuses
  22. INNER JOIN accounts ON accounts.id = statuses.account_id
  23. WHERE accounts.domain = :domain
  24. AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
  25. AND statuses.reblog_of_id IS NULL
  26. GROUP BY COALESCE(statuses.language, 'und')
  27. ORDER BY count(*) DESC
  28. LIMIT :limit
  29. SQL
  30. end
  31. def earliest_status_id
  32. Mastodon::Snowflake.id_at(@start_at, with_random: false)
  33. end
  34. def latest_status_id
  35. Mastodon::Snowflake.id_at(@end_at, with_random: false)
  36. end
  37. def params
  38. @params.permit(:domain)
  39. end
  40. end