PERF: Remove one extra call to Redis when searching.

PERF: Remove one extra call to Redis when searching.

diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 79c9b98..ee64025 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -69,7 +69,7 @@ class SearchController < ApplicationController
       result.error = I18n.t("search.extreme_load_error")
     else
       search = Search.new(@search_term, search_args)
-      result = search.execute
+      result = search.execute(readonly_mode: @readonly_mode)
       result.find_user_data(guardian) if result
     end
 
@@ -129,7 +129,7 @@ class SearchController < ApplicationController
       )
     else
       search = Search.new(params[:term], search_args)
-      result = search.execute
+      result = search.execute(readonly_mode: @readonly_mode)
     end
     render_serialized(result, GroupedSearchResultSerializer, result: result)
   end
diff --git a/lib/search.rb b/lib/search.rb
index ade1ee3..35adbf9 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -227,8 +227,8 @@ class Search
   end
 
   # Query a term
-  def execute
-    if SiteSetting.log_search_queries? && @opts[:search_type].present? && !Discourse.readonly_mode?
+  def execute(readonly_mode: Discourse.readonly_mode?)
+    if SiteSetting.log_search_queries? && @opts[:search_type].present? && !readonly_mode
       status, search_log_id = SearchLog.log(
         term: @term,
         search_type: @opts[:search_type],

GitHub sha: 3b08b158

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/babble-a-chat-plugin/87297/356