From bdc9e2f23063141e139818dee2755d7b21d5f6c9 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 17 Sep 2024 15:25:17 -0400 Subject: [PATCH] Extract identical preload call --- app/queries/account_search_query.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/queries/account_search_query.rb b/app/queries/account_search_query.rb index 155a6c10fa8..3c4fa4c0687 100644 --- a/app/queries/account_search_query.rb +++ b/app/queries/account_search_query.rb @@ -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`