Merge remote-tracking branch 'parent/main' into upstream-20240813

This commit is contained in:
KMY 2024-08-13 07:01:38 +09:00
commit e7ccc0539f
358 changed files with 4653 additions and 4261 deletions

View file

@ -281,6 +281,9 @@ class MediaAttachment < ApplicationRecord
before_create :set_unknown_type
before_create :set_processing
before_destroy :prepare_cache_bust!, prepend: true
after_destroy :bust_cache!
after_commit :enqueue_processing, on: :create
after_commit :reset_parent_cache, on: :update
@ -415,4 +418,29 @@ class MediaAttachment < ApplicationRecord
def reset_parent_cache
Rails.cache.delete("v3:statuses/#{status_id}") if status_id.present?
end
# Record the cache keys to burst before the file get actually deleted
def prepare_cache_bust!
return unless Rails.configuration.x.cache_buster_enabled
@paths_to_cache_bust = MediaAttachment.attachment_definitions.keys.flat_map do |attachment_name|
attachment = public_send(attachment_name)
styles = DEFAULT_STYLES | attachment.styles.keys
styles.map { |style| attachment.path(style) }
end
rescue => e
# We really don't want any error here preventing media deletion
Rails.logger.warn "Error #{e.class} busting cache: #{e.message}"
end
# Once Paperclip has deleted the files, we can't recover the cache keys,
# so use the previously-saved ones
def bust_cache!
return unless Rails.configuration.x.cache_buster_enabled
CacheBusterWorker.push_bulk(@paths_to_cache_bust) { |path| [path] }
rescue => e
# We really don't want any error here preventing media deletion
Rails.logger.warn "Error #{e.class} busting cache: #{e.message}"
end
end

View file

@ -4,17 +4,25 @@
#
# Table name: notification_policies
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# filter_not_following :boolean default(FALSE), not null
# filter_not_followers :boolean default(FALSE), not null
# filter_new_accounts :boolean default(FALSE), not null
# filter_private_mentions :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# created_at :datetime not null
# updated_at :datetime not null
# for_not_following :integer default("accept"), not null
# for_not_followers :integer default("accept"), not null
# for_new_accounts :integer default("accept"), not null
# for_private_mentions :integer default("filter"), not null
# for_limited_accounts :integer default("filter"), not null
#
class NotificationPolicy < ApplicationRecord
self.ignored_columns += %w(
filter_not_following
filter_not_followers
filter_new_accounts
filter_private_mentions
)
belongs_to :account
has_many :notification_requests, primary_key: :account_id, foreign_key: :account_id, dependent: nil, inverse_of: false
@ -23,11 +31,34 @@ class NotificationPolicy < ApplicationRecord
MAX_MEANINGFUL_COUNT = 100
enum :for_not_following, { accept: 0, filter: 1, drop: 2 }, suffix: :not_following
enum :for_not_followers, { accept: 0, filter: 1, drop: 2 }, suffix: :not_followers
enum :for_new_accounts, { accept: 0, filter: 1, drop: 2 }, suffix: :new_accounts
enum :for_private_mentions, { accept: 0, filter: 1, drop: 2 }, suffix: :private_mentions
enum :for_limited_accounts, { accept: 0, filter: 1, drop: 2 }, suffix: :limited_accounts
def summarize!
@pending_requests_count = pending_notification_requests.first
@pending_notifications_count = pending_notification_requests.last
end
# Compat helpers with V1
def filter_not_following=(value)
self.for_not_following = value ? :filter : :accept
end
def filter_not_followers=(value)
self.for_not_followers = value ? :filter : :accept
end
def filter_new_accounts=(value)
self.for_new_accounts = value ? :filter : :accept
end
def filter_private_mentions=(value)
self.for_private_mentions = value ? :filter : :accept
end
private
def pending_notification_requests

View file

@ -47,6 +47,6 @@ class NotificationRequest < ApplicationRecord
private
def prepare_notifications_count
self.notifications_count = Notification.where(account: account, from_account: from_account, filtered: true).limit(MAX_MEANINGFUL_COUNT).count
self.notifications_count = Notification.where(account: account, from_account: from_account, type: :mention, filtered: true).limit(MAX_MEANINGFUL_COUNT).count
end
end