]> cat aescling's git repositories - mastodon.git/commitdiff
Fix search error when ElasticSearch is enabled but not available (#11954)
authorJeong Arm <kjwonmail@gmail.com>
Thu, 26 Sep 2019 16:06:08 +0000 (01:06 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 26 Sep 2019 16:06:08 +0000 (18:06 +0200)
* Fallback to Database search when ES not available

* Prevent double work if ES gives 0 result

* Apply suggestion from code review

app/services/account_search_service.rb
app/services/tag_search_service.rb

index 01caaefa94fe2a6afa9df4bad8d4f41a57636532..40c5f8590c9888a5278adf7ca1485b4c35a3ca56 100644 (file)
@@ -42,11 +42,9 @@ class AccountSearchService < BaseService
     return [] if limit_for_non_exact_results.zero?
 
     @search_results ||= begin
-      if Chewy.enabled?
-        from_elasticsearch
-      else
-        from_database
-      end
+      results = from_elasticsearch if Chewy.enabled?
+      results ||= from_database
+      results
     end
   end
 
@@ -92,6 +90,8 @@ class AccountSearchService < BaseService
     ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
 
     records
+  rescue Faraday::ConnectionFailed, Parslet::ParseFailed
+    nil
   end
 
   def reputation_score_function
index 64dd76bb778d7c78c20e6e04262ee940b15edfd9..5cb0eea7a2f46134747110b7008b219a09143f72 100644 (file)
@@ -6,11 +6,10 @@ class TagSearchService < BaseService
     @offset = options[:offset].to_i
     @limit  = options[:limit].to_i
 
-    if Chewy.enabled?
-      from_elasticsearch
-    else
-      from_database
-    end
+    results = from_elasticsearch if Chewy.enabled?
+    results ||= from_database
+
+    results
   end
 
   private
@@ -74,6 +73,8 @@ class TagSearchService < BaseService
     }
 
     TagsIndex.query(query).filter(filter).limit(@limit).offset(@offset).objects.compact
+  rescue Faraday::ConnectionFailed, Parslet::ParseFailed
+    nil
   end
 
   def from_database