0
0
Fork 0

Rails 7 compatibility fix for Admin::Metrics::Dimension classes (#25277)

This commit is contained in:
Matt Jankowski 2023-06-05 10:52:33 -04:00 committed by GitHub
parent 70cd2d6000
commit 3b21c13dcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 297 additions and 44 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Dimension::BaseDimension
include Admin::Metrics::Dimension::QueryHelper
include LanguagesHelper
def self.with_params?
@ -14,21 +15,33 @@ class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Di
protected
def perform_query
sql = <<-SQL.squish
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
SELECT COALESCE(statuses.language, 'und') AS language, count(*) AS value
FROM statuses
INNER JOIN accounts ON accounts.id = statuses.account_id
WHERE accounts.domain = $1
AND statuses.id BETWEEN $2 AND $3
WHERE accounts.domain = :domain
AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id
AND statuses.reblog_of_id IS NULL
GROUP BY COALESCE(statuses.language, 'und')
ORDER BY count(*) DESC
LIMIT $4
LIMIT :limit
SQL
end
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:domain]], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, @limit]])
def earliest_status_id
Mastodon::Snowflake.id_at(@start_at, with_random: false)
end
rows.map { |row| { key: row['language'], human_key: standard_locale_name(row['language']), value: row['value'].to_s } }
def latest_status_id
Mastodon::Snowflake.id_at(@end_at, with_random: false)
end
def params