Fix n+1 queries in StatusThreadingConcern (#7321)
This commit is contained in:
parent
a3d84e705a
commit
a5293fdf61
4 changed files with 74 additions and 20 deletions
|
@ -3,9 +3,10 @@
|
|||
class StatusFilter
|
||||
attr_reader :status, :account
|
||||
|
||||
def initialize(status, account)
|
||||
@status = status
|
||||
@account = account
|
||||
def initialize(status, account, preloaded_relations = {})
|
||||
@status = status
|
||||
@account = account
|
||||
@preloaded_relations = preloaded_relations
|
||||
end
|
||||
|
||||
def filtered?
|
||||
|
@ -24,15 +25,15 @@ class StatusFilter
|
|||
end
|
||||
|
||||
def blocking_account?
|
||||
account.blocking? status.account_id
|
||||
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][status.account_id] : account.blocking?(status.account_id)
|
||||
end
|
||||
|
||||
def blocking_domain?
|
||||
account.domain_blocking? status.account_domain
|
||||
@preloaded_relations[:domain_blocking_by_domain] ? @preloaded_relations[:domain_blocking_by_domain][status.account_domain] : account.domain_blocking?(status.account_domain)
|
||||
end
|
||||
|
||||
def muting_account?
|
||||
account.muting? status.account_id
|
||||
@preloaded_relations[:muting] ? @preloaded_relations[:muting][status.account_id] : account.muting?(status.account_id)
|
||||
end
|
||||
|
||||
def silenced_account?
|
||||
|
@ -44,7 +45,7 @@ class StatusFilter
|
|||
end
|
||||
|
||||
def account_following_status_account?
|
||||
account&.following? status.account_id
|
||||
@preloaded_relations[:following] ? @preloaded_relations[:following][status.account_id] : account&.following?(status.account_id)
|
||||
end
|
||||
|
||||
def blocked_by_policy?
|
||||
|
@ -52,6 +53,6 @@ class StatusFilter
|
|||
end
|
||||
|
||||
def policy_allows_show?
|
||||
StatusPolicy.new(account, status).show?
|
||||
StatusPolicy.new(account, status, @preloaded_relations).show?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue