Fix call to inefficient delete_matched
cache method in domain blocks (#28374)
This commit is contained in:
parent
f4b9c2ba40
commit
7d9b209fe8
11 changed files with 96 additions and 50 deletions
|
@ -18,16 +18,12 @@ class AccountDomainBlock < ApplicationRecord
|
|||
belongs_to :account
|
||||
validates :domain, presence: true, uniqueness: { scope: :account_id }, domain: true
|
||||
|
||||
after_commit :remove_blocking_cache
|
||||
after_commit :remove_relationship_cache
|
||||
after_commit :invalidate_domain_blocking_cache
|
||||
|
||||
private
|
||||
|
||||
def remove_blocking_cache
|
||||
def invalidate_domain_blocking_cache
|
||||
Rails.cache.delete("exclude_domains_for:#{account_id}")
|
||||
end
|
||||
|
||||
def remove_relationship_cache
|
||||
Rails.cache.delete_matched("relationship:#{account_id}:*")
|
||||
Rails.cache.delete(['exclude_domains', account_id, domain])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -60,12 +60,6 @@ module Account::Interactions
|
|||
end
|
||||
end
|
||||
|
||||
def domain_blocking_map(target_account_ids, account_id)
|
||||
accounts_map = Account.where(id: target_account_ids).select('id, domain').each_with_object({}) { |a, h| h[a.id] = a.domain }
|
||||
blocked_domains = domain_blocking_map_by_domain(accounts_map.values.compact, account_id)
|
||||
accounts_map.reduce({}) { |h, (id, domain)| h.merge(id => blocked_domains[domain]) }
|
||||
end
|
||||
|
||||
def domain_blocking_map_by_domain(target_domains, account_id)
|
||||
follow_mapping(AccountDomainBlock.where(account_id: account_id, domain: target_domains), :domain)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module RelationshipCacheable
|
|||
private
|
||||
|
||||
def remove_relationship_cache
|
||||
Rails.cache.delete("relationship:#{account_id}:#{target_account_id}")
|
||||
Rails.cache.delete("relationship:#{target_account_id}:#{account_id}")
|
||||
Rails.cache.delete(['relationship', account_id, target_account_id])
|
||||
Rails.cache.delete(['relationship', target_account_id, account_id])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue