0
0
Fork 0

Fix n+1 queries in StatusThreadingConcern (#7321)

This commit is contained in:
Eugen Rochko 2018-05-03 10:41:58 +02:00 committed by GitHub
parent a3d84e705a
commit a5293fdf61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 20 deletions

View file

@ -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