Add emoji_reactions_count_per_account

This commit is contained in:
KMY 2023-04-14 10:20:15 +09:00
parent 1efc51313d
commit fed859a7d6
5 changed files with 28 additions and 13 deletions

View file

@ -318,6 +318,10 @@ class Status < ApplicationRecord
status_stat&.emoji_reactions_count || 0
end
def emoji_reactions_count_per_account
status_stat&.emoji_reactions_count_per_account || 0
end
def increment_count!(key)
update_status_stat!(key => public_send(key) + 1)
end
@ -345,7 +349,7 @@ class Status < ApplicationRecord
def refresh_emoji_reactions_grouped_by_name!
generate_emoji_reactions_grouped_by_name.tap do |emoji_reactions_json|
update_status_stat!(emoji_reactions: emoji_reactions_json, emoji_reactions_count: emoji_reactions.size)
update_status_stat!(emoji_reactions: emoji_reactions_json, emoji_reactions_count: emoji_reactions.size, emoji_reactions_count_per_account: emoji_reactions.map(&:account_id).uniq.size)
end
end

View file

@ -4,16 +4,17 @@
#
# Table name: status_stats
#
# id :bigint(8) not null, primary key
# status_id :bigint(8) not null
# replies_count :bigint(8) default(0), not null
# reblogs_count :bigint(8) default(0), not null
# favourites_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# emoji_reactions :string
# emoji_reactions_count :integer default(0), not null
# test :integer default(0), not null
# id :bigint(8) not null, primary key
# status_id :bigint(8) not null
# replies_count :bigint(8) default(0), not null
# reblogs_count :bigint(8) default(0), not null
# favourites_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# emoji_reactions :string
# emoji_reactions_count :integer default(0), not null
# test :integer default(0), not null
# emoji_reactions_count_per_account :integer default(0), not null
#
class StatusStat < ApplicationRecord
@ -41,6 +42,10 @@ class StatusStat < ApplicationRecord
[attributes['emoji_reactions_count'], 0].max
end
def emoji_reactions_count_per_account
[attributes['emoji_reactions_count_per_account'], 0].max
end
private
def reset_parent_cache

View file

@ -97,7 +97,7 @@ class Trends::Statuses < Trends::Base
def calculate_scores(statuses, at_time)
items = statuses.map do |status|
expected = 1.0
observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count * 0.3).to_f
observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count_per_account * 0.8).to_f
score = if expected > observed || observed < options[:threshold]
0