saved searches: remove option to disable saved searches.
Remove `SavedSearch.enabled?` checks. There's no need to make saved searches optional, since Redis is now required to run Danbooru.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
class SavedSearchesController < ApplicationController
|
||||
before_action :check_availability
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
def index
|
||||
@@ -39,12 +38,6 @@ class SavedSearchesController < ApplicationController
|
||||
CurrentUser.user.saved_searches
|
||||
end
|
||||
|
||||
def check_availability
|
||||
if !SavedSearch.enabled?
|
||||
raise NotImplementedError.new("Saved searches are not available.")
|
||||
end
|
||||
end
|
||||
|
||||
def saved_search_params
|
||||
params.fetch(:saved_search, {}).permit(%i[query label_string disable_labels])
|
||||
end
|
||||
|
||||
@@ -69,17 +69,15 @@ class PostQueryBuilder
|
||||
end
|
||||
|
||||
def add_saved_search_relation(saved_searches, relation)
|
||||
if SavedSearch.enabled?
|
||||
saved_searches.each do |saved_search|
|
||||
if saved_search == "all"
|
||||
post_ids = SavedSearch.post_ids_for(CurrentUser.id)
|
||||
else
|
||||
post_ids = SavedSearch.post_ids_for(CurrentUser.id, label: saved_search)
|
||||
end
|
||||
|
||||
post_ids = [0] if post_ids.empty?
|
||||
relation = relation.where("posts.id": post_ids)
|
||||
saved_searches.each do |saved_search|
|
||||
if saved_search == "all"
|
||||
post_ids = SavedSearch.post_ids_for(CurrentUser.id)
|
||||
else
|
||||
post_ids = SavedSearch.post_ids_for(CurrentUser.id, label: saved_search)
|
||||
end
|
||||
|
||||
post_ids = [0] if post_ids.empty?
|
||||
relation = relation.where("posts.id": post_ids)
|
||||
end
|
||||
|
||||
relation
|
||||
|
||||
@@ -2,10 +2,6 @@ class SavedSearch < ApplicationRecord
|
||||
REDIS_EXPIRY = 1.hour
|
||||
QUERY_LIMIT = 1000
|
||||
|
||||
def self.enabled?
|
||||
Danbooru.config.redis_url.present?
|
||||
end
|
||||
|
||||
concerning :Redis do
|
||||
extend Memoist
|
||||
|
||||
|
||||
@@ -95,11 +95,9 @@ class TagAlias < TagRelationship
|
||||
def move_saved_searches
|
||||
escaped = Regexp.escape(antecedent_name)
|
||||
|
||||
if SavedSearch.enabled?
|
||||
SavedSearch.where("query like ?", "%#{antecedent_name}%").find_each do |ss|
|
||||
ss.query = ss.query.sub(/(?:^| )#{escaped}(?:$| )/, " #{consequent_name} ").strip.gsub(/ /, " ")
|
||||
ss.save
|
||||
end
|
||||
SavedSearch.where("query like ?", "%#{antecedent_name}%").find_each do |ss|
|
||||
ss.query = ss.query.sub(/(?:^| )#{escaped}(?:$| )/, " #{consequent_name} ").strip.gsub(/ /, " ")
|
||||
ss.save
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<section id="options-box">
|
||||
<h1>Options</h1>
|
||||
<ul>
|
||||
<% if SavedSearch.enabled? && CurrentUser.is_member? %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<li><%= button_tag(tag.i(class: "fas fa-bookmark") + " Save search", id: "save-search", class: "ui-button ui-widget ui-corner-all sub") %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<% if SavedSearch.enabled? %>
|
||||
<div id="save-search-dialog" title="Save Search" style="display: none;">
|
||||
<div id="save-search-dialog" title="Save Search" style="display: none;">
|
||||
|
||||
<%= simple_form_for(SavedSearch.new, remote: true) do |f| %>
|
||||
<%= f.input :query, as: :string, input_html: { value: params[:tags], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited." %>
|
||||
<%= f.input :disable_labels, label: "Don't show this dialog again", as: :boolean %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= simple_form_for(SavedSearch.new, remote: true) do |f| %>
|
||||
<%= f.input :query, as: :string, input_html: { value: params[:tags], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :label_string, label: "Labels", hint: "A list of tags to help categorize this search. Space delimited." %>
|
||||
<%= f.input :disable_labels, label: "Don't show this dialog again", as: :boolean %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,6 @@ require 'test_helper'
|
||||
class SavedSearchesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The saved searches controller" do
|
||||
setup do
|
||||
SavedSearch.stubs(:enabled?).returns(true)
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@saved_search = create(:saved_search, user: @user)
|
||||
|
||||
@@ -61,7 +61,6 @@ class ActiveSupport::TestCase
|
||||
include ReportbooruHelper
|
||||
include DownloadTestHelper
|
||||
include IqdbTestHelper
|
||||
include SavedSearchTestHelper
|
||||
include UploadTestHelper
|
||||
include TestHelpers
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
module SavedSearchTestHelper
|
||||
def mock_saved_search_service!
|
||||
SavedSearch.stubs(:enabled?).returns(true)
|
||||
end
|
||||
end
|
||||
@@ -2256,7 +2256,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "saved searches" do
|
||||
setup do
|
||||
SavedSearch.stubs(:enabled?).returns(true)
|
||||
@post1 = FactoryBot.create(:post, tag_string: "aaa")
|
||||
@post2 = FactoryBot.create(:post, tag_string: "bbb")
|
||||
FactoryBot.create(:saved_search, query: "aaa", labels: ["zzz"], user: CurrentUser.user)
|
||||
|
||||
@@ -126,10 +126,6 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "saved searches" do
|
||||
setup do
|
||||
SavedSearch.stubs(:enabled?).returns(true)
|
||||
end
|
||||
|
||||
should "move saved searches" do
|
||||
tag1 = FactoryBot.create(:tag, :name => "...")
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
|
||||
Reference in New Issue
Block a user