Merge commit 'fed859a7d6
' into kb_migration
This commit is contained in:
commit
d52daef203
9 changed files with 42 additions and 13 deletions
|
@ -28,6 +28,7 @@ class EmojiReaction < ApplicationRecord
|
|||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validate :status_same_emoji_reaction
|
||||
validate :status_emoji_reactions_count
|
||||
|
||||
after_create :refresh_cache
|
||||
|
@ -53,6 +54,12 @@ class EmojiReaction < ApplicationRecord
|
|||
query
|
||||
end
|
||||
|
||||
def status_same_emoji_reaction
|
||||
if status && account && status.emoji_reactions.where(account: account).where(name: name).where(custom_emoji_id: custom_emoji_id).any?
|
||||
raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication')
|
||||
end
|
||||
end
|
||||
|
||||
def status_emoji_reactions_count
|
||||
if status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT
|
||||
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached')
|
||||
|
|
|
@ -315,6 +315,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
|
||||
|
@ -342,7 +346,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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue