Merge remote-tracking branch 'parent/main' into upstream-20240906

This commit is contained in:
KMY 2024-09-06 08:42:24 +09:00
commit f18eabfe75
689 changed files with 4369 additions and 2434 deletions

View file

@ -28,22 +28,18 @@ class AnnualReport::Archetype < AnnualReport::Source
end
def polls_count
@polls_count ||= base_scope.where.not(poll_id: nil).count
@polls_count ||= report_statuses.where.not(poll_id: nil).count
end
def reblogs_count
@reblogs_count ||= base_scope.where.not(reblog_of_id: nil).count
@reblogs_count ||= report_statuses.where.not(reblog_of_id: nil).count
end
def replies_count
@replies_count ||= base_scope.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count
@replies_count ||= report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count
end
def standalone_count
@standalone_count ||= base_scope.without_replies.without_reblogs.count
end
def base_scope
@account.statuses.where(id: year_as_snowflake_range)
@standalone_count ||= report_statuses.without_replies.without_reblogs.count
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::CommonlyInteractedWithAccounts < AnnualReport::Source
private
def commonly_interacted_with_accounts
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).where.not(in_reply_to_account_id: @account.id).group(:in_reply_to_account_id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('in_reply_to_account_id, count(*) AS total'))
report_statuses.where.not(in_reply_to_account_id: @account.id).group(:in_reply_to_account_id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('in_reply_to_account_id, count(*) AS total'))
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
private
def most_reblogged_accounts
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('accounts.id, count(*) as total'))
report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group('accounts.id').having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('accounts.id, count(*) as total'))
end
end

View file

@ -17,6 +17,6 @@ class AnnualReport::MostUsedApps < AnnualReport::Source
private
def most_used_apps
@account.statuses.reorder(nil).where(id: year_as_snowflake_range).joins(:application).group('oauth_applications.name').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('oauth_applications.name, count(*) as total'))
report_statuses.joins(:application).group('oauth_applications.name').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('oauth_applications.name, count(*) as total'))
end
end

View file

@ -17,7 +17,7 @@ class AnnualReport::Percentiles < AnnualReport::Source
end
def statuses_created
@statuses_created ||= @account.statuses.where(id: year_as_snowflake_range).count
@statuses_created ||= report_statuses.count
end
def total_with_fewer_followers

View file

@ -10,7 +10,24 @@ class AnnualReport::Source
protected
def report_statuses
@account
.statuses
.where(id: year_as_snowflake_range)
.reorder(nil)
end
def year_as_snowflake_range
(Mastodon::Snowflake.id_at(DateTime.new(year, 1, 1))..Mastodon::Snowflake.id_at(DateTime.new(year, 12, 31)))
(beginning_snowflake_id..ending_snowflake_id)
end
private
def beginning_snowflake_id
Mastodon::Snowflake.id_at DateTime.new(year).beginning_of_year
end
def ending_snowflake_id
Mastodon::Snowflake.id_at DateTime.new(year).end_of_year
end
end

View file

@ -17,7 +17,7 @@ class AnnualReport::TimeSeries < AnnualReport::Source
private
def statuses_per_month
@statuses_per_month ||= @account.statuses.reorder(nil).where(id: year_as_snowflake_range).group(:period).pluck(Arel.sql("date_part('month', created_at)::int AS period, count(*)")).to_h
@statuses_per_month ||= report_statuses.group(:period).pluck(Arel.sql("date_part('month', created_at)::int AS period, count(*)")).to_h
end
def following_per_month

View file

@ -17,6 +17,6 @@ class AnnualReport::TopHashtags < AnnualReport::Source
private
def top_hashtags
Tag.joins(:statuses).where(statuses: { id: @account.statuses.where(id: year_as_snowflake_range).reorder(nil).select(:id) }).group(:id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('COALESCE(tags.display_name, tags.name), count(*) AS total'))
Tag.joins(:statuses).where(statuses: { id: report_statuses.select(:id) }).group(:id).having('count(*) > 1').order(total: :desc).limit(SET_SIZE).pluck(Arel.sql('COALESCE(tags.display_name, tags.name), count(*) AS total'))
end
end

View file

@ -16,6 +16,6 @@ class AnnualReport::TopStatuses < AnnualReport::Source
end
def base_scope
@account.statuses.public_visibility.joins(:status_stat).where(id: year_as_snowflake_range).reorder(nil)
report_statuses.public_visibility.joins(:status_stat)
end
end

View file

@ -4,17 +4,11 @@ class AnnualReport::TypeDistribution < AnnualReport::Source
def generate
{
type_distribution: {
total: base_scope.count,
reblogs: base_scope.where.not(reblog_of_id: nil).count,
replies: base_scope.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
standalone: base_scope.without_replies.without_reblogs.count,
total: report_statuses.count,
reblogs: report_statuses.where.not(reblog_of_id: nil).count,
replies: report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
standalone: report_statuses.without_replies.without_reblogs.count,
},
}
end
private
def base_scope
@account.statuses.where(id: year_as_snowflake_range)
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class RedisConfiguration
class RedisConnection
class << self
def establish_pool(new_pool_size)
@pool&.shutdown(&:close)
@ -22,33 +22,24 @@ class RedisConfiguration
end
end
attr_reader :config
def initialize
@config = REDIS_CONFIGURATION.base
end
def connection
if namespace?
namespace = config[:namespace]
if namespace.present?
Redis::Namespace.new(namespace, redis: raw_connection)
else
raw_connection
end
end
def namespace?
namespace.present?
end
def namespace
ENV.fetch('REDIS_NAMESPACE', nil)
end
def url
ENV['REDIS_URL']
end
def redis_driver
ENV.fetch('REDIS_DRIVER', 'hiredis') == 'ruby' ? :ruby : :hiredis
end
private
def raw_connection
Redis.new(url: url, driver: redis_driver)
Redis.new(**config)
end
end