Only preload accounts in Collections when needed (#39143)
This commit is contained in:
1 parent
ae8b794c66
commit
dee85c6df9
4 files changed
+33
-7
No files matched your search
@@ -64,11 +64,15 @@ class Collection < ApplicationRecord
|
||||
!local?
|
||||
end
|
||||
|
||||
def items_for(account = nil)
|
||||
result = collection_items.with_accounts
|
||||
result = account == self.account ? result.pending_or_accepted : result.accepted
|
||||
result = result.not_blocked_by(account) unless account.nil?
|
||||
result
|
||||
def items_for(account = nil, include_accounts: false)
|
||||
@items_for ||= {}
|
||||
@items_for[account] ||= begin
|
||||
result = collection_items
|
||||
result = result.with_accounts if include_accounts
|
||||
result = account == self.account ? result.pending_or_accepted : result.accepted
|
||||
result = result.not_blocked_by(account) unless account.nil?
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def tag_name
|
||||
|
||||
@@ -43,7 +43,7 @@ class CollectionItem < ApplicationRecord
|
||||
|
||||
scope :ordered, -> { order(position: :asc) }
|
||||
scope :with_accounts, -> { includes(account: [:account_stat, :user]) }
|
||||
scope :not_blocked_by, ->(account) { where.not(accounts: { id: account.blocking }) }
|
||||
scope :not_blocked_by, ->(account) { joins(:account).where.not(accounts: { id: account.blocking }) }
|
||||
scope :local, -> { joins(:collection).merge(Collection.local) }
|
||||
scope :accepted_partial, ->(account) { joins(:account).merge(Account.local).accepted.where(uri: nil, account_id: account.id) }
|
||||
scope :pending_or_accepted, -> { where(state: [:pending, :accepted]) }
|
||||
|
||||
Reference in new issue
Block a user