Add emoji reactions to trends
This commit is contained in:
parent
bc48000dce
commit
e6fcf1543b
8 changed files with 33 additions and 14 deletions
|
@ -6,7 +6,7 @@ class PotentialFriendshipTracker
|
|||
|
||||
WEIGHTS = {
|
||||
reply: 1,
|
||||
emoji_reaction: 2,
|
||||
emoji_reaction: 3,
|
||||
favourite: 10,
|
||||
reblog: 20,
|
||||
}.freeze
|
||||
|
|
|
@ -28,6 +28,8 @@ class EmojiReaction < ApplicationRecord
|
|||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validate :status_emoji_reactions_count
|
||||
|
||||
after_create :refresh_cache
|
||||
after_destroy :refresh_cache
|
||||
after_destroy :invalidate_cleanup_info
|
||||
|
@ -50,4 +52,10 @@ class EmojiReaction < ApplicationRecord
|
|||
query = query.where(arel_table[:id].gt(since_id)) if since_id.present?
|
||||
query
|
||||
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')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -339,8 +339,8 @@ class Status < ApplicationRecord
|
|||
end
|
||||
|
||||
def refresh_emoji_reactions_grouped_by_name!
|
||||
generate_emoji_reactions_grouped_by_name.tap do |emoji_reactions|
|
||||
update_status_stat!(emoji_reactions: emoji_reactions)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
#
|
||||
# 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
|
||||
# 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
|
||||
#
|
||||
|
||||
class StatusStat < ApplicationRecord
|
||||
|
@ -35,6 +36,10 @@ class StatusStat < ApplicationRecord
|
|||
attributes['emoji_reactions'] || ''
|
||||
end
|
||||
|
||||
def emoji_reactions_count
|
||||
[attributes['emoji_reactions_count'], 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).to_f
|
||||
observed = (status.reblogs_count + status.favourites_count + status.emoji_reactions_count * 0.3).to_f
|
||||
|
||||
score = if expected > observed || observed < options[:threshold]
|
||||
0
|
||||
|
|
|
@ -53,7 +53,7 @@ class SearchService < BaseService
|
|||
privacy_definition = privacy_definition.or(StatusesIndex.filter(term: { searchability: 'direct' }).filter(term: { account_id: @account.id }).min_score(MIN_SCORE))
|
||||
end
|
||||
|
||||
definition = parsed_query.apply(StatusesIndex.min_score(MIN_SCORE)).order(id: :desc)
|
||||
definition = parsed_query.apply(StatusesIndex.min_score(MIN_SCORE).track_scores(true)).order(id: :desc)
|
||||
definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present?
|
||||
|
||||
definition = definition.and(privacy_definition)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddEmojiReactionsCountToStatusStats < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :status_stats, :emoji_reactions_count, :integer, null: false, default: 0
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_04_06_041523) do
|
||||
ActiveRecord::Schema.define(version: 2023_04_10_004651) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -933,6 +933,7 @@ ActiveRecord::Schema.define(version: 2023_04_06_041523) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "emoji_reactions"
|
||||
t.integer "emoji_reactions_count", default: 0, null: false
|
||||
t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue