Rails 7 compatibility fix for Admin::Metrics::Dimension
classes (#25277)
This commit is contained in:
parent
70cd2d6000
commit
3b21c13dcc
17 changed files with 297 additions and 44 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
include Admin::Metrics::Dimension::QueryHelper
|
||||
|
||||
def key
|
||||
'servers'
|
||||
end
|
||||
|
@ -8,18 +10,30 @@ class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::B
|
|||
protected
|
||||
|
||||
def perform_query
|
||||
sql = <<-SQL.squish
|
||||
dimension_data_rows.map { |row| { key: row['domain'] || Rails.configuration.x.local_domain, human_key: row['domain'] || Rails.configuration.x.local_domain, value: row['value'].to_s } }
|
||||
end
|
||||
|
||||
def sql_array
|
||||
[sql_query_string, { earliest_status_id: earliest_status_id, latest_status_id: latest_status_id, limit: @limit }]
|
||||
end
|
||||
|
||||
def sql_query_string
|
||||
<<~SQL.squish
|
||||
SELECT accounts.domain, count(*) AS value
|
||||
FROM statuses
|
||||
INNER JOIN accounts ON accounts.id = statuses.account_id
|
||||
WHERE statuses.id BETWEEN $1 AND $2
|
||||
WHERE statuses.id BETWEEN :earliest_status_id AND :latest_status_id
|
||||
GROUP BY accounts.domain
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT $3
|
||||
LIMIT :limit
|
||||
SQL
|
||||
end
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, Mastodon::Snowflake.id_at(@start_at)], [nil, Mastodon::Snowflake.id_at(@end_at)], [nil, @limit]])
|
||||
def earliest_status_id
|
||||
Mastodon::Snowflake.id_at(@start_at)
|
||||
end
|
||||
|
||||
rows.map { |row| { key: row['domain'] || Rails.configuration.x.local_domain, human_key: row['domain'] || Rails.configuration.x.local_domain, value: row['value'].to_s } }
|
||||
def latest_status_id
|
||||
Mastodon::Snowflake.id_at(@end_at)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue