Add emoji reaction option on status cleanup

This commit is contained in:
KMY 2023-04-20 17:40:25 +09:00
parent 3a1f268be2
commit 1a8e8f02dd
8 changed files with 41 additions and 6 deletions

View file

@ -30,7 +30,7 @@ class StatusesCleanupController < ApplicationController
end end
def resource_params def resource_params
params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :min_favs, :min_reblogs) params.require(:account_statuses_cleanup_policy).permit(:enabled, :min_status_age, :keep_direct, :keep_pinned, :keep_polls, :keep_media, :keep_self_fav, :keep_self_bookmark, :keep_self_emoji, :min_favs, :min_reblogs, :min_emojis)
end end
def set_body_classes def set_body_classes

View file

@ -18,6 +18,8 @@
# min_reblogs :integer # min_reblogs :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# min_emojis :integer
# keep_self_emoji :boolean default(TRUE), not null
# #
class AccountStatusesCleanupPolicy < ApplicationRecord class AccountStatusesCleanupPolicy < ApplicationRecord
include Redisable include Redisable
@ -33,8 +35,8 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
2.years.seconds, 2.years.seconds,
].freeze ].freeze
EXCEPTION_BOOLS = %w(keep_direct keep_pinned keep_polls keep_media keep_self_fav keep_self_bookmark).freeze EXCEPTION_BOOLS = %w(keep_direct keep_pinned keep_polls keep_media keep_self_fav keep_self_bookmark keep_self_emoji).freeze
EXCEPTION_THRESHOLDS = %w(min_favs min_reblogs).freeze EXCEPTION_THRESHOLDS = %w(min_favs min_reblogs min_emojis).freeze
# Depending on the cleanup policy, the query to discover the next # Depending on the cleanup policy, the query to discover the next
# statuses to delete my get expensive if the account has a lot of old # statuses to delete my get expensive if the account has a lot of old
@ -52,6 +54,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
validates :min_status_age, inclusion: { in: ALLOWED_MIN_STATUS_AGE } validates :min_status_age, inclusion: { in: ALLOWED_MIN_STATUS_AGE }
validates :min_favs, numericality: { greater_than_or_equal_to: 1, allow_nil: true } validates :min_favs, numericality: { greater_than_or_equal_to: 1, allow_nil: true }
validates :min_reblogs, numericality: { greater_than_or_equal_to: 1, allow_nil: true } validates :min_reblogs, numericality: { greater_than_or_equal_to: 1, allow_nil: true }
validates :min_emojis, numericality: { greater_than_or_equal_to: 1, allow_nil: true }
validate :validate_local_account validate :validate_local_account
before_save :update_last_inspected before_save :update_last_inspected
@ -60,13 +63,14 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
scope = account.statuses scope = account.statuses
scope.merge!(old_enough_scope(max_id)) scope.merge!(old_enough_scope(max_id))
scope = scope.where(Status.arel_table[:id].gteq(min_id)) if min_id.present? scope = scope.where(Status.arel_table[:id].gteq(min_id)) if min_id.present?
scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil? scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil? && min_emojis.nil?
scope.merge!(without_direct_scope) if keep_direct? scope.merge!(without_direct_scope) if keep_direct?
scope.merge!(without_pinned_scope) if keep_pinned? scope.merge!(without_pinned_scope) if keep_pinned?
scope.merge!(without_poll_scope) if keep_polls? scope.merge!(without_poll_scope) if keep_polls?
scope.merge!(without_media_scope) if keep_media? scope.merge!(without_media_scope) if keep_media?
scope.merge!(without_self_fav_scope) if keep_self_fav? scope.merge!(without_self_fav_scope) if keep_self_fav?
scope.merge!(without_self_bookmark_scope) if keep_self_bookmark? scope.merge!(without_self_bookmark_scope) if keep_self_bookmark?
scope.merge!(without_self_emoji_scope) if keep_self_emoji?
scope.reorder(id: :asc).limit(limit) scope.reorder(id: :asc).limit(limit)
end end
@ -107,6 +111,8 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
return unless keep_self_bookmark? return unless keep_self_bookmark?
when :unfav when :unfav
return unless keep_self_fav? return unless keep_self_fav?
when :unemoji
return unless keep_self_emoji?
when :unpin when :unpin
return unless keep_pinned? return unless keep_pinned?
end end
@ -148,6 +154,10 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
Status.where('NOT EXISTS (SELECT * FROM favourites fav WHERE fav.account_id = statuses.account_id AND fav.status_id = statuses.id)') Status.where('NOT EXISTS (SELECT * FROM favourites fav WHERE fav.account_id = statuses.account_id AND fav.status_id = statuses.id)')
end end
def without_self_emoji_scope
Status.where('NOT EXISTS (SELECT * FROM emoji_reactions emj WHERE emj.account_id = statuses.account_id AND emj.status_id = statuses.id)')
end
def without_self_bookmark_scope def without_self_bookmark_scope
Status.where('NOT EXISTS (SELECT * FROM bookmarks bookmark WHERE bookmark.account_id = statuses.account_id AND bookmark.status_id = statuses.id)') Status.where('NOT EXISTS (SELECT * FROM bookmarks bookmark WHERE bookmark.account_id = statuses.account_id AND bookmark.status_id = statuses.id)')
end end
@ -168,6 +178,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
scope = Status.left_joins(:status_stat) scope = Status.left_joins(:status_stat)
scope = scope.where('COALESCE(status_stats.reblogs_count, 0) < ?', min_reblogs) unless min_reblogs.nil? scope = scope.where('COALESCE(status_stats.reblogs_count, 0) < ?', min_reblogs) unless min_reblogs.nil?
scope = scope.where('COALESCE(status_stats.favourites_count, 0) < ?', min_favs) unless min_favs.nil? scope = scope.where('COALESCE(status_stats.favourites_count, 0) < ?', min_favs) unless min_favs.nil?
scope = scope.where('COALESCE(status_stats.emoji_reactions_count, 0) < ?', min_emojis) unless min_emojis.nil?
scope scope
end end
end end

View file

@ -44,7 +44,7 @@ class EmojiReaction < ApplicationRecord
def invalidate_cleanup_info def invalidate_cleanup_info
return unless status&.account_id == account_id && account.local? return unless status&.account_id == account_id && account.local?
account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unfav) account.statuses_cleanup_policy&.invalidate_last_inspected(status, :unemoji)
end end
def paginate_by_max_id(limit, max_id = nil, since_id = nil) def paginate_by_max_id(limit, max_id = nil, since_id = nil)

View file

@ -34,6 +34,10 @@
.fields-row__column.fields-row__column-6.fields-group .fields-row__column.fields-row__column-6.fields-group
= f.input :keep_media, wrapper: :with_label, label: t('statuses_cleanup.keep_media'), hint: t('statuses_cleanup.keep_media_hint') = f.input :keep_media, wrapper: :with_label, label: t('statuses_cleanup.keep_media'), hint: t('statuses_cleanup.keep_media_hint')
.fields-row
.fields-row__column.fields-row__column-6.fields-group
= f.input :keep_self_emoji, wrapper: :with_label, label: t('statuses_cleanup.keep_self_emoji'), hint: t('statuses_cleanup.keep_self_emoji_hint')
%h4= t('statuses_cleanup.interaction_exceptions') %h4= t('statuses_cleanup.interaction_exceptions')
.fields-row .fields-row
@ -42,4 +46,8 @@
.fields-row__column.fields-row__column-6.fields-group .fields-row__column.fields-row__column-6.fields-group
= f.input :min_reblogs, wrapper: :with_label, label: t('statuses_cleanup.min_reblogs'), hint: t('statuses_cleanup.min_reblogs_hint'), input_html: { min: 1, placeholder: t('statuses_cleanup.ignore_reblogs') } = f.input :min_reblogs, wrapper: :with_label, label: t('statuses_cleanup.min_reblogs'), hint: t('statuses_cleanup.min_reblogs_hint'), input_html: { min: 1, placeholder: t('statuses_cleanup.ignore_reblogs') }
.fields-row
.fields-row__column.fields-row__column-6.fields-group
= f.input :min_emojis, wrapper: :with_label, label: t('statuses_cleanup.min_emojis'), hint: t('statuses_cleanup.min_emojis_hint'), input_html: { min: 1, placeholder: t('statuses_cleanup.ignore_emojis') }
.flash-message= t('statuses_cleanup.interaction_exceptions_explanation') .flash-message= t('statuses_cleanup.interaction_exceptions_explanation')

View file

@ -1601,6 +1601,7 @@ en:
enabled_hint: Automatically deletes your posts once they reach a specified age threshold, unless they match one of the exceptions below enabled_hint: Automatically deletes your posts once they reach a specified age threshold, unless they match one of the exceptions below
exceptions: Exceptions exceptions: Exceptions
explanation: Because deleting posts is an expensive operation, this is done slowly over time when the server is not otherwise busy. For this reason, your posts may be deleted a while after they reach the age threshold. explanation: Because deleting posts is an expensive operation, this is done slowly over time when the server is not otherwise busy. For this reason, your posts may be deleted a while after they reach the age threshold.
ignore_emojis: Ignore emoji reactions
ignore_favs: Ignore favourites ignore_favs: Ignore favourites
ignore_reblogs: Ignore boosts ignore_reblogs: Ignore boosts
interaction_exceptions: Exceptions based on interactions interaction_exceptions: Exceptions based on interactions
@ -1627,6 +1628,8 @@ en:
'63113904': 2 years '63113904': 2 years
'7889238': 3 months '7889238': 3 months
min_age_label: Age threshold min_age_label: Age threshold
min_emojis: Keep posts emoji-reacted at least
min_emojis_hint: Doesn't delete any of your posts that has received at least this number of emoji reactions. Leave blank to delete posts regardless of their number of emojis
min_favs: Keep posts favourited at least min_favs: Keep posts favourited at least
min_favs_hint: Doesn't delete any of your posts that has received at least this number of favourites. Leave blank to delete posts regardless of their number of favourites min_favs_hint: Doesn't delete any of your posts that has received at least this number of favourites. Leave blank to delete posts regardless of their number of favourites
min_reblogs: Keep posts boosted at least min_reblogs: Keep posts boosted at least

View file

@ -1562,6 +1562,7 @@ ja:
enabled_hint: 設定した期間を過ぎた投稿は、以下の例外に該当しない限り、自動的に削除されます enabled_hint: 設定した期間を過ぎた投稿は、以下の例外に該当しない限り、自動的に削除されます
exceptions: 例外 exceptions: 例外
explanation: 投稿の削除はサーバーに負荷がかかるため、サーバーが混み合っていないときに時間をかけて行われます。 explanation: 投稿の削除はサーバーに負荷がかかるため、サーバーが混み合っていないときに時間をかけて行われます。
ignore_emojis: 設定しない
ignore_favs: 設定しない ignore_favs: 設定しない
ignore_reblogs: 設定しない ignore_reblogs: 設定しない
interaction_exceptions: インタラクションに基づく例外 interaction_exceptions: インタラクションに基づく例外
@ -1576,6 +1577,8 @@ ja:
keep_polls_hint: アンケート付きの投稿を削除せずに残します keep_polls_hint: アンケート付きの投稿を削除せずに残します
keep_self_bookmark: ブックマークした投稿を保持 keep_self_bookmark: ブックマークした投稿を保持
keep_self_bookmark_hint: 自分自身でブックマークした投稿を削除せずに残します keep_self_bookmark_hint: 自分自身でブックマークした投稿を削除せずに残します
keep_self_emoji: 絵文字リアクションした投稿を保持
keep_self_emoji_hint: 自分自身で絵文字リアクションした投稿を削除せずに残します
keep_self_fav: お気に入りに登録した投稿を保持 keep_self_fav: お気に入りに登録した投稿を保持
keep_self_fav_hint: 自分自身でお気に入りに登録した投稿を削除せずに残します keep_self_fav_hint: 自分自身でお気に入りに登録した投稿を削除せずに残します
min_age: min_age:
@ -1588,6 +1591,8 @@ ja:
'63113904': 2年 '63113904': 2年
'7889238': 3ヶ月 '7889238': 3ヶ月
min_age_label: 投稿を保持する期間 min_age_label: 投稿を保持する期間
min_emojis: 絵文字リアクションの基準値
min_emojis_hint: この数以上、絵文字リアクションされた投稿を削除せずに残します。空白にしておくと、数に関わらず投稿を削除します。
min_favs: お気に入りの基準値 min_favs: お気に入りの基準値
min_favs_hint: この数以上、お気に入り登録された投稿を削除せずに残します。空白にしておくと、お気に入りの数に関わらず投稿を削除します。 min_favs_hint: この数以上、お気に入り登録された投稿を削除せずに残します。空白にしておくと、お気に入りの数に関わらず投稿を削除します。
min_reblogs: ブーストの基準値 min_reblogs: ブーストの基準値

View file

@ -0,0 +1,6 @@
class AddMinEmojisToAccountStatusesCleanupPolicies < ActiveRecord::Migration[6.1]
def change
add_column :account_statuses_cleanup_policies, :min_emojis, :integer
add_column :account_statuses_cleanup_policies, :keep_self_emoji, :boolean, default: true, null: false
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_04_14_010523) do ActiveRecord::Schema.define(version: 2023_04_20_081634) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -117,6 +117,8 @@ ActiveRecord::Schema.define(version: 2023_04_14_010523) do
t.integer "min_reblogs" t.integer "min_reblogs"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.integer "min_emojis"
t.boolean "keep_self_emoji", default: true, null: false
t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id" t.index ["account_id"], name: "index_account_statuses_cleanup_policies_on_account_id"
end end