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
|
class SavedSearchesController < ApplicationController
|
||||||
before_action :check_availability
|
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@@ -39,12 +38,6 @@ class SavedSearchesController < ApplicationController
|
|||||||
CurrentUser.user.saved_searches
|
CurrentUser.user.saved_searches
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_availability
|
|
||||||
if !SavedSearch.enabled?
|
|
||||||
raise NotImplementedError.new("Saved searches are not available.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def saved_search_params
|
def saved_search_params
|
||||||
params.fetch(:saved_search, {}).permit(%i[query label_string disable_labels])
|
params.fetch(:saved_search, {}).permit(%i[query label_string disable_labels])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,17 +69,15 @@ class PostQueryBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_saved_search_relation(saved_searches, relation)
|
def add_saved_search_relation(saved_searches, relation)
|
||||||
if SavedSearch.enabled?
|
saved_searches.each do |saved_search|
|
||||||
saved_searches.each do |saved_search|
|
if saved_search == "all"
|
||||||
if saved_search == "all"
|
post_ids = SavedSearch.post_ids_for(CurrentUser.id)
|
||||||
post_ids = SavedSearch.post_ids_for(CurrentUser.id)
|
else
|
||||||
else
|
post_ids = SavedSearch.post_ids_for(CurrentUser.id, label: saved_search)
|
||||||
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
|
end
|
||||||
|
|
||||||
|
post_ids = [0] if post_ids.empty?
|
||||||
|
relation = relation.where("posts.id": post_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
relation
|
relation
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ class SavedSearch < ApplicationRecord
|
|||||||
REDIS_EXPIRY = 1.hour
|
REDIS_EXPIRY = 1.hour
|
||||||
QUERY_LIMIT = 1000
|
QUERY_LIMIT = 1000
|
||||||
|
|
||||||
def self.enabled?
|
|
||||||
Danbooru.config.redis_url.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
concerning :Redis do
|
concerning :Redis do
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,9 @@ class TagAlias < TagRelationship
|
|||||||
def move_saved_searches
|
def move_saved_searches
|
||||||
escaped = Regexp.escape(antecedent_name)
|
escaped = Regexp.escape(antecedent_name)
|
||||||
|
|
||||||
if SavedSearch.enabled?
|
SavedSearch.where("query like ?", "%#{antecedent_name}%").find_each do |ss|
|
||||||
SavedSearch.where("query like ?", "%#{antecedent_name}%").find_each do |ss|
|
ss.query = ss.query.sub(/(?:^| )#{escaped}(?:$| )/, " #{consequent_name} ").strip.gsub(/ /, " ")
|
||||||
ss.query = ss.query.sub(/(?:^| )#{escaped}(?:$| )/, " #{consequent_name} ").strip.gsub(/ /, " ")
|
ss.save
|
||||||
ss.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<section id="options-box">
|
<section id="options-box">
|
||||||
<h1>Options</h1>
|
<h1>Options</h1>
|
||||||
<ul>
|
<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>
|
<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 %>
|
<% end %>
|
||||||
</ul>
|
</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| %>
|
<%= 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 :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 :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 %>
|
<%= f.input :disable_labels, label: "Don't show this dialog again", as: :boolean %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ require 'test_helper'
|
|||||||
class SavedSearchesControllerTest < ActionDispatch::IntegrationTest
|
class SavedSearchesControllerTest < ActionDispatch::IntegrationTest
|
||||||
context "The saved searches controller" do
|
context "The saved searches controller" do
|
||||||
setup do
|
setup do
|
||||||
SavedSearch.stubs(:enabled?).returns(true)
|
|
||||||
@user = create(:user)
|
@user = create(:user)
|
||||||
as_user do
|
as_user do
|
||||||
@saved_search = create(:saved_search, user: @user)
|
@saved_search = create(:saved_search, user: @user)
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class ActiveSupport::TestCase
|
|||||||
include ReportbooruHelper
|
include ReportbooruHelper
|
||||||
include DownloadTestHelper
|
include DownloadTestHelper
|
||||||
include IqdbTestHelper
|
include IqdbTestHelper
|
||||||
include SavedSearchTestHelper
|
|
||||||
include UploadTestHelper
|
include UploadTestHelper
|
||||||
include TestHelpers
|
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
|
context "saved searches" do
|
||||||
setup do
|
setup do
|
||||||
SavedSearch.stubs(:enabled?).returns(true)
|
|
||||||
@post1 = FactoryBot.create(:post, tag_string: "aaa")
|
@post1 = FactoryBot.create(:post, tag_string: "aaa")
|
||||||
@post2 = FactoryBot.create(:post, tag_string: "bbb")
|
@post2 = FactoryBot.create(:post, tag_string: "bbb")
|
||||||
FactoryBot.create(:saved_search, query: "aaa", labels: ["zzz"], user: CurrentUser.user)
|
FactoryBot.create(:saved_search, query: "aaa", labels: ["zzz"], user: CurrentUser.user)
|
||||||
|
|||||||
@@ -126,10 +126,6 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "saved searches" do
|
context "saved searches" do
|
||||||
setup do
|
|
||||||
SavedSearch.stubs(:enabled?).returns(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "move saved searches" do
|
should "move saved searches" do
|
||||||
tag1 = FactoryBot.create(:tag, :name => "...")
|
tag1 = FactoryBot.create(:tag, :name => "...")
|
||||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||||
|
|||||||
Reference in New Issue
Block a user