diff --git a/app/assets/javascripts/autocomplete.js b/app/assets/javascripts/autocomplete.js index 943b64e35..e70200f39 100644 --- a/app/assets/javascripts/autocomplete.js +++ b/app/assets/javascripts/autocomplete.js @@ -93,7 +93,7 @@ var prefixes = "-|~|general:|gen:|artist:|art:|copyright:|copy:|co:|character:|char:|ch:"; var metatags = "order|-status|status|-rating|rating|-locked|locked|child|filetype|-filetype|" + "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-fav|fav|ordfav|" + - "sub|-pool|pool|ordpool|favgroup|-search|search"; + "-pool|pool|ordpool|favgroup|-search|search"; $fields_multiple.autocomplete({ delay: 100, diff --git a/app/assets/stylesheets/specific/tag_subscriptions.scss b/app/assets/stylesheets/specific/tag_subscriptions.scss index 9fd68c2b3..c353a0780 100644 --- a/app/assets/stylesheets/specific/tag_subscriptions.scss +++ b/app/assets/stylesheets/specific/tag_subscriptions.scss @@ -7,12 +7,6 @@ div#c-tag-subscriptions { font-style: italic; } - div#a-posts { - h1 { - font-size: $h3_size; - } - } - .hint { display: block; } diff --git a/app/controllers/tag_subscriptions_controller.rb b/app/controllers/tag_subscriptions_controller.rb index 6eab9c6a0..ae0d34869 100644 --- a/app/controllers/tag_subscriptions_controller.rb +++ b/app/controllers/tag_subscriptions_controller.rb @@ -1,19 +1,7 @@ class TagSubscriptionsController < ApplicationController - before_filter :disable_feature, :only => [:create] - before_filter :member_only, :only => [:new, :edit, :create, :update, :destroy, :migrate] + before_filter :member_only, :only => [:destroy, :migrate] respond_to :html, :xml, :json - def new - @tag_subscription = TagSubscription.new - respond_with(@tag_subscription) - end - - def edit - @tag_subscription = TagSubscription.find(params[:id]) - check_privilege(@tag_subscription) - respond_with(@tag_subscription) - end - def index @user = CurrentUser.user @query = TagSubscription.order("name").search(params[:search]) @@ -21,34 +9,6 @@ class TagSubscriptionsController < ApplicationController respond_with(@tag_subscriptions) end - def create - @tag_subscription = TagSubscription.create(params[:tag_subscription]) - respond_with(@tag_subscription) do |format| - format.html do - if @tag_subscription.errors.any? - render :action => "new" - else - redirect_to tag_subscriptions_path - end - end - end - end - - def update - @tag_subscription = TagSubscription.find(params[:id]) - check_privilege(@tag_subscription) - @tag_subscription.update_attributes(params[:tag_subscription]) - respond_with(@tag_subscription) do |format| - format.html do - if @tag_subscription.errors.any? - render :action => "edit" - else - redirect_to tag_subscriptions_path - end - end - end - end - def destroy @tag_subscription = TagSubscription.find(params[:id]) check_privilege(@tag_subscription) @@ -56,12 +16,6 @@ class TagSubscriptionsController < ApplicationController respond_with(@tag_subscription) end - def posts - @user = User.find(params[:id]) - @post_set = PostSets::Post.new("sub:#{@user.name} #{params[:tags]}", params[:page]) - @posts = @post_set.posts - end - def migrate @tag_subscription = TagSubscription.find(params[:id]) check_privilege(@tag_subscription) @@ -71,12 +25,6 @@ class TagSubscriptionsController < ApplicationController end private - def disable_feature - flash[:notice] = "Tag subscriptions are disabled" - redirect_to tag_subscriptions_path - return false - end - def check_privilege(tag_subscription) raise User::PrivilegeError unless tag_subscription.editable_by?(CurrentUser.user) end diff --git a/app/helpers/delayed_jobs_helper.rb b/app/helpers/delayed_jobs_helper.rb index 13d75c5f3..97cdd92f4 100644 --- a/app/helpers/delayed_jobs_helper.rb +++ b/app/helpers/delayed_jobs_helper.rb @@ -13,9 +13,6 @@ module DelayedJobsHelper when "Moderator::TagBatchChange" "tag batch change" - when "TagSubscription.process" - "process tag subscription" - when "Class#expire_cache" "expire post count cache" @@ -40,9 +37,6 @@ module DelayedJobsHelper when "Tag#update_category_post_counts" "update category post counts" - when "Class#process" - "update tag subscription" - when "Class#remove_iqdb" "remove from iqdb" @@ -80,9 +74,6 @@ module DelayedJobsHelper when "Moderator::TagBatchChange" h(job.payload_object.antecedent) + " -> " + h(job.payload_object.consequent) - when "TagSubscription.process" - "" - when "Class#expire_cache" h(job.payload_object.args.flatten.join(" ")) diff --git a/app/models/tag.rb b/app/models/tag.rb index b3a08c0e5..8fe96d00f 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,6 +1,6 @@ class Tag < ApplicationRecord COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000 - METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer" + METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer" SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer" attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin] attr_accessible :is_locked, :as => [:moderator, :admin] diff --git a/app/models/tag_subscription.rb b/app/models/tag_subscription.rb index 8dd929746..a9e25d72f 100644 --- a/app/models/tag_subscription.rb +++ b/app/models/tag_subscription.rb @@ -1,13 +1,7 @@ class TagSubscription < ApplicationRecord belongs_to :creator, :class_name => "User" - before_validation :initialize_creator, :on => :create - before_validation :initialize_post_ids, :on => :create - before_save :normalize_name - before_save :limit_tag_count attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile validates_presence_of :name, :tag_query, :creator_id - validate :validate_number_of_queries - validate :creator_can_create_subscriptions, :on => :create def migrate_to_saved_searches tag_query.split(/\r\n|\r|\n/).each do |query| @@ -15,10 +9,6 @@ class TagSubscription < ApplicationRecord end end - def normalize_name - self.name = name.gsub(/\s+/, "_") - end - def pretty_name name.tr("_", " ") end @@ -27,60 +17,14 @@ class TagSubscription < ApplicationRecord tag_query_array.join(", ") end - def initialize_creator - self.creator_id = CurrentUser.id - end - - def initialize_post_ids - process - end - - def creator_can_create_subscriptions - if TagSubscription.owned_by(creator).count >= Danbooru.config.max_tag_subscriptions - self.errors.add(:creator, "can create up to #{Danbooru.config.max_tag_subscriptions} tag subscriptions") - return false - else - return true - end - end - - def validate_number_of_queries - if tag_query_array.size > 20 || tag_query_array.size < 1 - self.errors.add(:tag_query, "can have up to 20 queries") - return false - else - return true - end - end - def tag_query_array tag_query.scan(/[^\r\n]+/).map(&:strip) end - def limit_tag_count - # self.tag_query = tag_query_array.slice(0, 20).join(" ") - end - - def process - divisor = [tag_query_array.size / 2, 1].max - post_ids = tag_query_array.inject([]) do |all, query| - all += PostReadOnly.tag_match(query).limit(Danbooru.config.tag_subscription_post_limit / divisor).select("posts.id").order("posts.id DESC").map(&:id) - end - self.post_ids = post_ids.sort.reverse.slice(0, Danbooru.config.tag_subscription_post_limit).join(",") - end - - def is_active? - creator.is_gold? && creator.last_logged_in_at && creator.last_logged_in_at > 3.months.ago - end - def editable_by?(user) user.is_moderator? || creator_id == user.id end - def post_id_array - post_ids.split(/,/) - end - module SearchMethods def visible_to(user) where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?) @@ -117,71 +61,4 @@ class TagSubscription < ApplicationRecord end extend SearchMethods - - def self.find_tags(subscription_name) - if subscription_name =~ /^(.+?):(.+)$/ - user_name = $1 - sub_group = $2 - else - user_name = subscription_name - sub_group = nil - end - - user = User.find_by_name(user_name) - - if user - relation = where(["creator_id = ?", user.id]) - - if sub_group - relation = relation.where(["name ILIKE ? ESCAPE E'\\\\'", sub_group.to_escaped_for_sql_like]) - end - - relation.map {|x| x.tag_query_array}.flatten - else - [] - end - end - - def self.find_post_ids(user_id, name = nil, limit = Danbooru.config.tag_subscription_post_limit) - relation = where("creator_id = ?", user_id) - - if name - relation = relation.where("lower(name) LIKE ? ESCAPE E'\\\\'", name.mb_chars.downcase.to_escaped_for_sql_like) - end - - relation.each do |tag_sub| - tag_sub.update_column(:last_accessed_at, Time.now) - end - - relation.map {|x| x.post_ids.split(/,/)}.flatten.uniq.map(&:to_i).sort.reverse.slice(0, limit) - end - - def self.find_posts(user_id, name = nil, limit = Danbooru.config.tag_subscription_post_limit) - arel = Post.where(["id in (?)", find_post_ids(user_id, name, limit)]) - - if CurrentUser.user.hide_deleted_posts? - arel = arel.where("is_deleted = false") - end - - arel.order("id DESC").limit(limit) - end - - def self.process(id) - tag_subscription = TagSubscription.find(id) - CurrentUser.scoped(tag_subscription.creator, "127.0.0.1") do - tag_subscription.process - tag_subscription.save - end - rescue Exception => x - raise if Rails.env != "production" - end - - def self.process_all - find_each do |tag_subscription| - if tag_subscription.is_active? - time = rand(20 * 60 * 60).seconds.from_now - TagSubscription.delay(:run_at => time, :queue => "default", :priority => 10).process(tag_subscription.id) - end - end - end end diff --git a/app/views/tag_subscriptions/_form.html.erb b/app/views/tag_subscriptions/_form.html.erb deleted file mode 100644 index 4602ea30b..000000000 --- a/app/views/tag_subscriptions/_form.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<%= simple_form_for(@tag_subscription) do |f| %> - <%= f.input :name %> - <%= f.input :tag_query, :hint => "Put separate tag combinations on separate lines.", :input_html => {:size => "40x5"} %> -
This feature is disabled.
- - <%#= error_messages_for "tag_subscription" %> - - <%#= render "form" %> -