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"} %> -
- -
- <%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %> -<% end %> diff --git a/app/views/tag_subscriptions/_secondary_links.html.erb b/app/views/tag_subscriptions/_secondary_links.html.erb index 7ffcc40da..4a42f0f56 100644 --- a/app/views/tag_subscriptions/_secondary_links.html.erb +++ b/app/views/tag_subscriptions/_secondary_links.html.erb @@ -6,7 +6,6 @@ <% if @tag_subscription && !@tag_subscription.new_record? && @tag_subscription.editable_by?(CurrentUser.user) %>
  • |
  • <%= link_to "Show", tag_subscription_path(@tag_subscription) %>
  • -
  • <%= link_to "Edit", edit_tag_subscription_path(@tag_subscription) %>
  • <%= link_to "Delete", tag_subscription_path(@tag_subscription, :method => :delete, :data => {:confirm => "Are you sure you want to delete this tag subscription?"}) %>
  • <% end %> diff --git a/app/views/tag_subscriptions/edit.html.erb b/app/views/tag_subscriptions/edit.html.erb deleted file mode 100644 index a5c3d39c3..000000000 --- a/app/views/tag_subscriptions/edit.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -
    -
    -

    Edit Tag Subscription

    - - <%= error_messages_for "tag_subscription" %> - - <%= render "form" %> -
    -
    - -<% content_for(:page_title) do %> - Edit Tag Subscription - <%= Danbooru.config.app_name %> -<% end %> diff --git a/app/views/tag_subscriptions/index.html.erb b/app/views/tag_subscriptions/index.html.erb index 321bbbc46..d1f05b37f 100644 --- a/app/views/tag_subscriptions/index.html.erb +++ b/app/views/tag_subscriptions/index.html.erb @@ -9,7 +9,6 @@ Name Tag Query - Count @@ -18,7 +17,6 @@ <%= tag_subscription.pretty_name %> <%= tag_subscription.pretty_tag_query %> - <%= tag_subscription.post_id_array.size %> <%= link_to "delete", tag_subscription_path(tag_subscription), :method => :delete, :data => {:confirm => "Are you sure you want to delete this subscription?"} %> | <%= link_to "migrate", migrate_tag_subscription_path(tag_subscription), :method => :post %> diff --git a/app/views/tag_subscriptions/new.html.erb b/app/views/tag_subscriptions/new.html.erb deleted file mode 100644 index 244837f64..000000000 --- a/app/views/tag_subscriptions/new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -
    -
    -

    New Tag Subscription

    - -

    This feature is disabled.

    - - <%#= error_messages_for "tag_subscription" %> - - <%#= render "form" %> -
    -
    - -<% content_for(:page_title) do %> - New Tag Subscription - <%= Danbooru.config.app_name %> -<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2bb27b559..3a1e57cde 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -269,10 +269,9 @@ Rails.application.routes.draw do end end resource :tag_implication_request, :only => [:new, :create] - resources :tag_subscriptions do + resources :tag_subscriptions, :only => [:index, :destroy, :migrate] do member do post :migrate - get :posts end end resources :uploads do diff --git a/test/functional/tag_subscriptions_controller_test.rb b/test/functional/tag_subscriptions_controller_test.rb index 2a449cbb7..7935de110 100644 --- a/test/functional/tag_subscriptions_controller_test.rb +++ b/test/functional/tag_subscriptions_controller_test.rb @@ -24,43 +24,6 @@ class TagSubscriptionsControllerTest < ActionController::TestCase end end - context "posts action" do - setup do - @tag_subscription = FactoryGirl.create(:tag_subscription, :name => "aaa") - end - - should "list all visible tag subscriptions" do - get :posts, {:id => @tag_subscription.creator_id} - assert_response :success - end - end - - context "edit action" do - setup do - @tag_subscription = FactoryGirl.create(:tag_subscription) - end - - should "render" do - get :edit, {:id => @tag_subscription.id}, {:user_id => @user.id} - assert_response :success - end - end - - context "new action" do - should "render" do - get :new, {}, {:user_id => @user.id} - assert_response :success - end - end - - context "create action" do - should "not create a new tag subscription" do - assert_no_difference("TagSubscription.count") do - post :create, {:tag_subscription => {:name => "aaa", :tag_query => "bbb"}}, {:user_id => @user.id} - end - end - end - context "destroy action" do setup do @tag_subscription = FactoryGirl.create(:tag_subscription) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 89e847373..04127d3e4 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2019,14 +2019,6 @@ class PostTest < ActiveSupport::TestCase # assert_equal(1, Post.tag_match("pixiv_novel_id:2156088").count) # end - should "return posts for a tag subscription search" do - post1 = FactoryGirl.create(:post, :tag_string => "aaa") - sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz") - TagSubscription.process_all - relation = Post.tag_match("sub:#{CurrentUser.name}") - assert_equal(1, relation.count) - end - should "return posts for a search: metatag" do post1 = FactoryGirl.create(:post, tag_string: "aaa") post2 = FactoryGirl.create(:post, tag_string: "bbb") diff --git a/test/unit/tag_subscription_test.rb b/test/unit/tag_subscription_test.rb index ba6215d1b..d5ba531f2 100644 --- a/test/unit/tag_subscription_test.rb +++ b/test/unit/tag_subscription_test.rb @@ -13,66 +13,6 @@ class TagSubscriptionTest < ActiveSupport::TestCase end context "A tag subscription" do - context "for a user with too many subscriptions" do - setup do - Danbooru.config.stubs(:max_tag_subscriptions).returns(0) - @user = FactoryGirl.create(:user) - end - - should "fail" do - sub = FactoryGirl.build(:tag_subscription, :tag_query => "aaa\nbbb", :creator => @user, :name => "zzz") - sub.save - assert_equal(["You can create up to 0 tag subscriptions"], sub.errors.full_messages) - end - end - - should "find the union of all posts for each tag in its tag query" do - posts = [] - user = FactoryGirl.create(:user) - posts << FactoryGirl.create(:post, :tag_string => "aaa") - posts << FactoryGirl.create(:post, :tag_string => "bbb") - posts << FactoryGirl.create(:post, :tag_string => "ccc") - posts << FactoryGirl.create(:post, :tag_string => "ddd") - CurrentUser.scoped(user, "127.0.0.1") do - sub_1 = FactoryGirl.create(:tag_subscription, :tag_query => "aaa\nbbb", :name => "zzz") - sub_2 = FactoryGirl.create(:tag_subscription, :tag_query => "ccc", :name => "yyy") - assert_equal([posts[1].id, posts[0].id], TagSubscription.find_posts(user.id, "zzz").map(&:id)) - assert_equal([posts[2].id, posts[1].id, posts[0].id], TagSubscription.find_posts(user.id).map(&:id)) - end - end - - should "cache its tag query results" do - posts = [] - user = FactoryGirl.create(:user) - posts << FactoryGirl.create(:post, :tag_string => "aaa") - posts << FactoryGirl.create(:post, :tag_string => "bbb") - posts << FactoryGirl.create(:post, :tag_string => "ccc") - CurrentUser.scoped(user, "127.0.0.1") do - sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa\nbbb", :name => "zzz") - assert_equal("#{posts[1].id},#{posts[0].id}", sub.post_ids) - end - end - - should "find posts based on its cached post ids" do - user = FactoryGirl.create(:user) - CurrentUser.scoped(user, "127.0.0.1") do - subs = [] - subs << FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz") - subs << FactoryGirl.create(:tag_subscription, :tag_query => "bbb", :name => "yyy") - assert_equal([], TagSubscription.find_posts(user.id)) - assert_equal([], TagSubscription.find_posts(user.id, "zzz")) - assert_equal([], TagSubscription.find_posts(user.id, "yyy")) - posts = [] - posts << FactoryGirl.create(:post, :tag_string => "aaa") - posts << FactoryGirl.create(:post, :tag_string => "bbb") - posts << FactoryGirl.create(:post, :tag_string => "ccc") - subs.each {|x| x.process; x.save} - assert_equal([posts[1].id, posts[0].id], TagSubscription.find_posts(user.id).map(&:id)) - assert_equal([posts[0].id], TagSubscription.find_posts(user.id, "zzz").map(&:id)) - assert_equal([posts[1].id], TagSubscription.find_posts(user.id, "yyy").map(&:id)) - end - end - should "migrate to saved searches" do sub = FactoryGirl.create(:tag_subscription, tag_query: "foo bar\r\nbar\nbaz", :name => "Artist 1") sub.migrate_to_saved_searches @@ -83,27 +23,4 @@ class TagSubscriptionTest < ActiveSupport::TestCase assert_equal([%w[artist_1]]*3, CurrentUser.user.saved_searches.pluck(:labels)) end end - - context "A tag subscription manager" do - should "process all active tag subscriptions" do - users = [] - users << FactoryGirl.create(:user) - users << FactoryGirl.create(:user) - posts = [] - posts << FactoryGirl.create(:post, :tag_string => "aaa") - posts << FactoryGirl.create(:post, :tag_string => "bbb") - posts << FactoryGirl.create(:post, :tag_string => "ccc") - subscriptions = [] - CurrentUser.scoped(users[0], "127.0.0.1") do - subscriptions << FactoryGirl.create(:tag_subscription, :tag_query => "aaa") - end - CurrentUser.scoped(users[1], "127.0.0.1") do - subscriptions << FactoryGirl.create(:tag_subscription, :tag_query => "bbb") - end - TagSubscription.process_all - subscriptions.each {|x| x.reload} - assert_equal("#{posts[0].id}", subscriptions[0].post_ids) - assert_equal("#{posts[1].id}", subscriptions[1].post_ids) - end - end end