saved searches: fix failure when search returns no results.

* Don't try to call `sadd` when a search returns no results (`sadd`
  fails in this case).
* Add a timeout when populating the search.
* Don't offload the search to read replica. The main db is fine.
* Disable synchronous population of searches. This was too slow.
This commit is contained in:
evazion
2019-09-02 20:42:01 -05:00
parent 4abffc7faa
commit 2841f0742c
3 changed files with 28 additions and 11 deletions

View File

@@ -123,6 +123,23 @@ class SavedSearchTest < ActiveSupport::TestCase
end
end
context "Populating a saved search" do
setup do
@saved_search = create(:saved_search, query: "bkub", user: @user)
@post = create(:post, tag_string: "bkub")
end
should "work for a single tag search" do
SavedSearch.populate("bkub")
assert_equal([@post.id], SavedSearch.post_ids_for(@user.id))
end
should "work for a tag search returning no posts" do
SavedSearch.populate("does_not_exist")
assert_equal([], SavedSearch.post_ids_for(@user.id))
end
end
context "Creating a saved search" do
setup do
FactoryBot.create(:tag_alias, antecedent_name: "zzz", consequent_name: "yyy", creator: @user)