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:
evazion
2019-09-22 23:04:22 -05:00
parent c33c33500e
commit 4e4c4d627e
11 changed files with 19 additions and 48 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -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>