mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 03:25:17 +01:00
Extract identical preload call
This commit is contained in:
parent
a72d8a6132
commit
bdc9e2f230
@ -116,18 +116,25 @@ class AccountSearchQuery
|
||||
|
||||
def search
|
||||
Account.find_by_sql([BASIC_SEARCH_SQL, { limit: @limit, offset: @offset, tsquery: generate_query_for_search }]).tap do |records|
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: [:account_stat, { user: :role }]).call
|
||||
preload(records)
|
||||
end
|
||||
end
|
||||
|
||||
def advanced_search(account, following: false)
|
||||
Account.find_by_sql([advanced_sql_template(following), { id: account.id, limit: @limit, offset: @offset, tsquery: generate_query_for_search }]).tap do |records|
|
||||
ActiveRecord::Associations::Preloader.new(records: records, associations: [:account_stat, { user: :role }]).call
|
||||
preload(records)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def preload(records)
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: records,
|
||||
associations: [:account_stat, { user: :role }]
|
||||
).call
|
||||
end
|
||||
|
||||
def generate_query_for_search
|
||||
# The final ":*" is for prefix search.
|
||||
# The trailing space does not seem to fit any purpose, but `to_tsquery`
|
||||
|
Loading…
Reference in New Issue
Block a user