Revert "Upstream 20240517"

This commit is contained in:
KMY(雪あすか) 2024-05-24 08:15:12 +09:00 committed by GitHub
parent 9c006fd893
commit f6dec44e95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2347 changed files with 26470 additions and 87494 deletions

View file

@ -18,8 +18,6 @@
# min_reblogs :integer
# created_at :datetime not null
# updated_at :datetime not null
# min_emojis :integer
# keep_self_emoji :boolean default(TRUE), not null
#
class AccountStatusesCleanupPolicy < ApplicationRecord
include Redisable
@ -35,8 +33,8 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
2.years.seconds,
].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 min_emojis).freeze
EXCEPTION_BOOLS = %w(keep_direct keep_pinned keep_polls keep_media keep_self_fav keep_self_bookmark).freeze
EXCEPTION_THRESHOLDS = %w(min_favs min_reblogs).freeze
# 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
@ -54,7 +52,6 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
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_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
before_save :update_last_inspected
@ -63,14 +60,13 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
scope = account_statuses
scope.merge!(old_enough_scope(max_id))
scope = scope.where(id: min_id..) if min_id.present?
scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil? && min_emojis.nil?
scope.merge!(without_popular_scope) unless min_favs.nil? && min_reblogs.nil?
scope.merge!(without_direct_scope) if keep_direct?
scope.merge!(without_pinned_scope) if keep_pinned?
scope.merge!(without_poll_scope) if keep_polls?
scope.merge!(without_media_scope) if keep_media?
scope.merge!(without_self_fav_scope) if keep_self_fav?
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)
end
@ -111,8 +107,6 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
return unless keep_self_bookmark?
when :unfav
return unless keep_self_fav?
when :unemoji
return unless keep_self_emoji?
when :unpin
return unless keep_pinned?
end
@ -154,10 +148,6 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
Status.where('NOT EXISTS (SELECT 1 FROM favourites fav WHERE fav.account_id = statuses.account_id AND fav.status_id = statuses.id)')
end
def without_self_emoji_scope
Status.where('NOT EXISTS (SELECT 1 FROM emoji_reactions emj WHERE emj.account_id = statuses.account_id AND emj.status_id = statuses.id)')
end
def without_self_bookmark_scope
Status.where('NOT EXISTS (SELECT 1 FROM bookmarks bookmark WHERE bookmark.account_id = statuses.account_id AND bookmark.status_id = statuses.id)')
end
@ -178,7 +168,6 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
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.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
end