Add trending links (#16917)
* Add trending links * Add overriding specific links trendability * Add link type to preview cards and only trend articles Change trends review notifications from being sent every 5 minutes to being sent every 2 hours Change threshold from 5 unique accounts to 15 unique accounts * Fix tests
This commit is contained in:
parent
46e62fc4b3
commit
6e50134a42
97 changed files with 2071 additions and 722 deletions
|
@ -1,10 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::BaseDimension
|
||||
def initialize(start_at, end_at, limit)
|
||||
def self.with_params?
|
||||
false
|
||||
end
|
||||
|
||||
def initialize(start_at, end_at, limit, params)
|
||||
@start_at = start_at&.to_datetime
|
||||
@end_at = end_at&.to_datetime
|
||||
@limit = limit&.to_i
|
||||
@params = params
|
||||
end
|
||||
|
||||
def key
|
||||
|
@ -26,6 +31,10 @@ class Admin::Metrics::Dimension::BaseDimension
|
|||
protected
|
||||
|
||||
def time_period
|
||||
(@start_at...@end_at)
|
||||
(@start_at..@end_at)
|
||||
end
|
||||
|
||||
def params
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
include LanguagesHelper
|
||||
|
||||
def key
|
||||
'languages'
|
||||
end
|
||||
|
@ -18,6 +20,6 @@ class Admin::Metrics::Dimension::LanguagesDimension < Admin::Metrics::Dimension:
|
|||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, @limit]])
|
||||
|
||||
rows.map { |row| { key: row['locale'], human_key: SettingsHelper::HUMAN_LOCALES[row['locale'].to_sym], value: row['value'].to_s } }
|
||||
rows.map { |row| { key: row['locale'], human_key: human_locale(row['locale']), value: row['value'].to_s } }
|
||||
end
|
||||
end
|
||||
|
|
36
app/lib/admin/metrics/dimension/tag_languages_dimension.rb
Normal file
36
app/lib/admin/metrics/dimension/tag_languages_dimension.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::TagLanguagesDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
include LanguagesHelper
|
||||
|
||||
def self.with_params?
|
||||
true
|
||||
end
|
||||
|
||||
def key
|
||||
'tag_languages'
|
||||
end
|
||||
|
||||
def data
|
||||
sql = <<-SQL.squish
|
||||
SELECT COALESCE(statuses.language, 'und') AS language, count(*) AS value
|
||||
FROM statuses
|
||||
INNER JOIN statuses_tags ON statuses_tags.status_id = statuses.id
|
||||
WHERE statuses_tags.tag_id = $1
|
||||
AND statuses.id BETWEEN $2 AND $3
|
||||
GROUP BY COALESCE(statuses.language, 'und')
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT $4
|
||||
SQL
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:id]], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, @limit]])
|
||||
|
||||
rows.map { |row| { key: row['language'], human_key: human_locale(row['language']), value: row['value'].to_s } }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params
|
||||
@params.permit(:id)
|
||||
end
|
||||
end
|
35
app/lib/admin/metrics/dimension/tag_servers_dimension.rb
Normal file
35
app/lib/admin/metrics/dimension/tag_servers_dimension.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Dimension::TagServersDimension < Admin::Metrics::Dimension::BaseDimension
|
||||
def self.with_params?
|
||||
true
|
||||
end
|
||||
|
||||
def key
|
||||
'tag_servers'
|
||||
end
|
||||
|
||||
def data
|
||||
sql = <<-SQL.squish
|
||||
SELECT accounts.domain, count(*) AS value
|
||||
FROM statuses
|
||||
INNER JOIN accounts ON accounts.id = statuses.account_id
|
||||
INNER JOIN statuses_tags ON statuses_tags.status_id = statuses.id
|
||||
WHERE statuses_tags.tag_id = $1
|
||||
AND statuses.id BETWEEN $2 AND $3
|
||||
GROUP BY accounts.domain
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT $4
|
||||
SQL
|
||||
|
||||
rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:id]], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, @limit]])
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def params
|
||||
@params.permit(:id)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue