Remove unused tag subscription code (#2956, #3206).

This commit is contained in:
evazion
2017-07-13 13:44:26 -05:00
parent d3d4e3cc8d
commit 3e3844a796
15 changed files with 4 additions and 365 deletions

View File

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

View File

@@ -7,12 +7,6 @@ div#c-tag-subscriptions {
font-style: italic;
}
div#a-posts {
h1 {
font-size: $h3_size;
}
}
.hint {
display: block;
}

View File

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

View File

@@ -13,9 +13,6 @@ module DelayedJobsHelper
when "Moderator::TagBatchChange"
"<strong>tag batch change</strong>"
when "TagSubscription.process"
"<strong>process tag subscription</strong>"
when "Class#expire_cache"
"<strong>expire post count cache</strong>"
@@ -40,9 +37,6 @@ module DelayedJobsHelper
when "Tag#update_category_post_counts"
"<strong>update category post counts</strong>"
when "Class#process"
"<strong>update tag subscription</strong>"
when "Class#remove_iqdb"
"<strong>remove from iqdb</strong>"
@@ -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(" "))

View File

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

View File

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

View File

@@ -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"} %>
<div class="input">
<label for="tag_subscription_is_public">
<%= check_box "tag_subscription", "is_public" %>
Is Public
</label>
</div>
<%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %>
<% end %>

View File

@@ -6,7 +6,6 @@
<% if @tag_subscription && !@tag_subscription.new_record? && @tag_subscription.editable_by?(CurrentUser.user) %>
<li>|</li>
<li><%= link_to "Show", tag_subscription_path(@tag_subscription) %></li>
<li><%= link_to "Edit", edit_tag_subscription_path(@tag_subscription) %></li>
<li><%= link_to "Delete", tag_subscription_path(@tag_subscription, :method => :delete, :data => {:confirm => "Are you sure you want to delete this tag subscription?"}) %></li>
<% end %>
</menu>

View File

@@ -1,13 +0,0 @@
<div id="c-tag-subscriptions">
<div id="a-edit">
<h1>Edit Tag Subscription</h1>
<%= error_messages_for "tag_subscription" %>
<%= render "form" %>
</div>
</div>
<% content_for(:page_title) do %>
Edit Tag Subscription - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -9,7 +9,6 @@
<tr>
<th>Name</th>
<th>Tag Query</th>
<th>Count</th>
<th></th>
</tr>
</thead>
@@ -18,7 +17,6 @@
<tr>
<td><%= tag_subscription.pretty_name %></td>
<td><%= tag_subscription.pretty_tag_query %></td>
<td><%= tag_subscription.post_id_array.size %></td>
<td>
<%= 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 %>

View File

@@ -1,15 +0,0 @@
<div id="c-tag-subscriptions">
<div id="a-new">
<h1>New Tag Subscription</h1>
<p class="info">This feature is disabled.</p>
<%#= error_messages_for "tag_subscription" %>
<%#= render "form" %>
</div>
</div>
<% content_for(:page_title) do %>
New Tag Subscription - <%= Danbooru.config.app_name %>
<% end %>

View File

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

View File

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

View File

@@ -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:<category> metatag" do
post1 = FactoryGirl.create(:post, tag_string: "aaa")
post2 = FactoryGirl.create(:post, tag_string: "bbb")

View File

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