Add emoji_reactions_count
This commit is contained in:
parent
7aebdd8740
commit
95bb69a626
9 changed files with 33 additions and 11 deletions
|
@ -41,7 +41,7 @@ module Admin::ActionLogsHelper
|
|||
when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
|
||||
link_to attributes['domain'], "https://#{attributes['domain']}"
|
||||
when 'Status'
|
||||
tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
|
||||
tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count', 'emoji_reactions_count', 'emoji_reactions_cache'))
|
||||
|
||||
if tmp_status.account
|
||||
link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
|
||||
|
|
|
@ -192,7 +192,7 @@ class DetailedStatus extends ImmutablePureComponent {
|
|||
|
||||
const reblogsCount = status.get('reblogs_count');
|
||||
const favouritesCount = status.get('favourites_count');
|
||||
const emojiReactionsCount = status.get('emoji_reactions').reduce( (accumulator, reaction) => accumulator + reaction.get('count'), 0 );
|
||||
const emojiReactionsCount = status.get('emoji_reactions_count');
|
||||
|
||||
if (this.props.measureHeight) {
|
||||
outerStyle.height = `${this.state.height}px`;
|
||||
|
|
|
@ -299,6 +299,10 @@ class Status < ApplicationRecord
|
|||
status_stat&.favourites_count || 0
|
||||
end
|
||||
|
||||
def emoji_reactions_count
|
||||
status_stat&.emoji_reactions_count || 0
|
||||
end
|
||||
|
||||
def grouped_emoji_reactions(account = nil)
|
||||
(Oj.load(status_stat&.emoji_reactions_cache || '', mode: :strict) || []).tap do |emoji_reactions|
|
||||
if account.present?
|
||||
|
@ -318,7 +322,7 @@ class Status < ApplicationRecord
|
|||
|
||||
def refresh_grouped_emoji_reactions!
|
||||
generate_grouped_emoji_reactions.tap do |emoji_reactions_cache|
|
||||
update_status_stat!(emoji_reactions_cache: emoji_reactions_cache)
|
||||
update_status_stat!(emoji_reactions_count: emoji_reactions.count, emoji_reactions_cache: emoji_reactions_cache)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
# replies_count :bigint(8) default(0), not null
|
||||
# reblogs_count :bigint(8) default(0), not null
|
||||
# favourites_count :bigint(8) default(0), not null
|
||||
# emoji_reactions_count :bigint(8) default(0), not null
|
||||
# emoji_reactions_cache :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# emoji_reactions_cache :string default(""), not null
|
||||
#
|
||||
|
||||
class StatusStat < ApplicationRecord
|
||||
|
|
|
@ -4,7 +4,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
|
|||
attributes :id, :created_at, :in_reply_to_id, :in_reply_to_account_id,
|
||||
:sensitive, :spoiler_text, :visibility, :language,
|
||||
:uri, :url, :replies_count, :reblogs_count,
|
||||
:favourites_count, :emoji_reactions
|
||||
:favourites_count, :emoji_reactions_count, :emoji_reactions
|
||||
|
||||
attribute :favourited, if: :current_user?
|
||||
attribute :reblogged, if: :current_user?
|
||||
|
|
|
@ -150,7 +150,7 @@ class DeleteAccountService < BaseService
|
|||
purge_generated_notifications!
|
||||
purge_favourites!
|
||||
purge_bookmarks!
|
||||
purge_reactions!
|
||||
purge_emoji_reactions!
|
||||
purge_feeds!
|
||||
purge_other_associations!
|
||||
|
||||
|
@ -203,10 +203,10 @@ class DeleteAccountService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def purge_reactions!
|
||||
@account.emoji_reactions.in_batches do |reactions|
|
||||
Chewy.strategy.current.update(StatusesIndex, reactions.pluck(:status_id)) if Chewy.enabled?
|
||||
reactions.delete_all
|
||||
def purge_emoji_reactions!
|
||||
@account.emoji_reactions.in_batches do |emoji_reactions|
|
||||
Chewy.strategy.current.update(StatusesIndex, emoji_reactions.pluck(:status_id)) if Chewy.enabled?
|
||||
emoji_reactions.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
|
||||
|
||||
class AddEmojiReactionsCountToStatusStat < ActiveRecord::Migration[6.1]
|
||||
include Mastodon::MigrationHelpers
|
||||
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
safety_assured { add_column_with_default :status_stats, :emoji_reactions_count, :bigint, default: 0, allow_null: false }
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :status_stats, :emoji_reactions_count
|
||||
end
|
||||
end
|
|
@ -949,9 +949,10 @@ ActiveRecord::Schema.define(version: 2021_12_13_040746) do
|
|||
t.bigint "replies_count", default: 0, null: false
|
||||
t.bigint "reblogs_count", default: 0, null: false
|
||||
t.bigint "favourites_count", default: 0, null: false
|
||||
t.bigint "emoji_reactions_count", default: 0, null: false
|
||||
t.string "emoji_reactions_cache", default: "", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "emoji_reactions_cache", default: "", null: false
|
||||
t.index ["status_id"], name: "index_status_stats_on_status_id", unique: true
|
||||
end
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ module Mastodon
|
|||
status_stat.replies_count = status.replies.where.not(visibility: :direct).count
|
||||
status_stat.reblogs_count = status.reblogs.count
|
||||
status_stat.favourites_count = status.favourites.count
|
||||
status_stat.emoji_reactions_count = status.emoji_reactions.count
|
||||
status_stat.emoji_reactions_cache = status.generate_grouped_emoji_reactions
|
||||
|
||||
status_stat.save if status_stat.changed?
|
||||
|
|
Loading…
Reference in a new issue