forked from e621ng/e621ng
[Cleanup] Remove TagChangeNoticeService
This commit is contained in:
parent
ec658c4cb3
commit
10d09700fb
@ -97,10 +97,6 @@ module PostsHelper
|
||||
return params[:post_set_id].to_i == post_set.id
|
||||
end
|
||||
|
||||
def show_tag_change_notice?
|
||||
Tag.scan_query(params[:tags]).size == 1 && TagChangeNoticeService.get_forum_topic_id(params[:tags])
|
||||
end
|
||||
|
||||
def post_stats_section(post)
|
||||
status_flags = []
|
||||
status_flags << 'P' if post.parent_id
|
||||
|
@ -170,31 +170,7 @@ class AliasAndImplicationImporter
|
||||
end
|
||||
end
|
||||
|
||||
def affected_tags
|
||||
tokens = self.class.tokenize(text)
|
||||
tokens.inject([]) do |all, token|
|
||||
case token[0]
|
||||
when :create_alias, :remove_alias, :create_implication, :remove_implication
|
||||
all << token[1]
|
||||
all << token[2]
|
||||
all
|
||||
|
||||
when :mass_update
|
||||
all += Tag.scan_tags(token[1])
|
||||
all += Tag.scan_tags(token[2])
|
||||
all
|
||||
|
||||
when :change_category
|
||||
all << token[1]
|
||||
all
|
||||
|
||||
else
|
||||
all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
## These functions will find and appropriate existing aliases or implications if needed. This reduces friction with accepting
|
||||
# a BUR, and makes it much easier to work with.
|
||||
|
@ -1,19 +0,0 @@
|
||||
module TagChangeNoticeService
|
||||
extend self
|
||||
|
||||
def redis_client
|
||||
::Redis.new(url: Danbooru.config.redis_url)
|
||||
end
|
||||
|
||||
def get_forum_topic_id(tag)
|
||||
false #redis_client.get("tcn:#{tag}")
|
||||
end
|
||||
|
||||
def update_cache(affected_tags, forum_topic_id)
|
||||
# TODO: Revisit this idea and making it work with some kind of cache invalidation.
|
||||
# rc = redis_client
|
||||
# affected_tags.each do |tag|
|
||||
# rc.setex("tcn:#{tag}", 1.week, forum_topic_id)
|
||||
# end
|
||||
end
|
||||
end
|
@ -17,7 +17,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
before_validation :initialize_attributes, :on => :create
|
||||
before_validation :normalize_text
|
||||
after_create :create_forum_topic
|
||||
after_save :update_notice
|
||||
|
||||
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
|
||||
scope :pending, -> {where(status: "pending")}
|
||||
@ -257,11 +256,4 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
def estimate_update_count
|
||||
AliasAndImplicationImporter.new(self, script, nil).estimate_update_count
|
||||
end
|
||||
|
||||
def update_notice
|
||||
TagChangeNoticeService.update_cache(
|
||||
AliasAndImplicationImporter.new(self, script, nil).affected_tags,
|
||||
forum_topic_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -30,7 +30,6 @@ class TagRelationship < ApplicationRecord
|
||||
validates :antecedent_name, tag_name: { disable_ascii_check: true }, on: :create
|
||||
validates :consequent_name, tag_name: true, on: :create
|
||||
validate :antecedent_and_consequent_are_different
|
||||
after_save :update_notice
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
@ -209,13 +208,6 @@ class TagRelationship < ApplicationRecord
|
||||
Post.fast_count(antecedent_name, skip_cache: true)
|
||||
end
|
||||
|
||||
def update_notice
|
||||
TagChangeNoticeService.update_cache(
|
||||
[antecedent_name, consequent_name],
|
||||
forum_topic_id
|
||||
)
|
||||
end
|
||||
|
||||
def update_posts
|
||||
Post.without_timeout do
|
||||
Post.sql_raw_tag_match(antecedent_name).find_each do |post|
|
||||
|
@ -20,12 +20,6 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if show_tag_change_notice? %>
|
||||
<div class="tag-change-notice">
|
||||
<p>This tag is the subject of an ongoing discussion. If you have any relevant information, please join the <%= link_to "discussion", forum_topic_path(TagChangeNoticeService.get_forum_topic_id(params[:tags]) || 1) %>.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% unless post_set.is_random? %>
|
||||
<%= numbered_paginator(post_set.posts) %>
|
||||
<% end %>
|
||||
|
@ -26,28 +26,6 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "#affected_tags" do
|
||||
setup do
|
||||
FactoryBot.create(:post, tag_string: "aaa")
|
||||
FactoryBot.create(:post, tag_string: "bbb")
|
||||
FactoryBot.create(:post, tag_string: "ccc")
|
||||
FactoryBot.create(:post, tag_string: "ddd")
|
||||
FactoryBot.create(:post, tag_string: "eee")
|
||||
|
||||
@script = "create alias aaa -> 000\n" +
|
||||
"create implication bbb -> 111\n" +
|
||||
"remove alias ccc -> 222\n" +
|
||||
"remove implication ddd -> 333\n" +
|
||||
"mass update eee -> 444\n"
|
||||
end
|
||||
|
||||
subject { AliasAndImplicationImporter.new(@script, nil) }
|
||||
|
||||
should "return the correct tags" do
|
||||
assert_equal(%w(aaa 000 bbb 111 ccc 222 ddd 333 eee 444), subject.affected_tags)
|
||||
end
|
||||
end
|
||||
|
||||
context "#estimate_update_count" do
|
||||
setup do
|
||||
FactoryBot.create(:post, tag_string: "aaa")
|
||||
|
@ -35,33 +35,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "#update_notice" do
|
||||
setup do
|
||||
@mock_redis = MockRedis.new
|
||||
@forum_topic = FactoryBot.create(:forum_topic)
|
||||
TagChangeNoticeService.stubs(:redis_client).returns(@mock_redis)
|
||||
end
|
||||
|
||||
should "update redis" do
|
||||
@script = "create alias aaa -> 000\n" +
|
||||
"create implication bbb -> 111\n" +
|
||||
"remove alias ccc -> 222\n" +
|
||||
"remove implication ddd -> 333\n" +
|
||||
"mass update eee -> 444\n"
|
||||
FactoryBot.create(:bulk_update_request, script: @script, forum_topic: @forum_topic)
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:aaa"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:000"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:bbb"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:111"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:ccc"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:222"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:ddd"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:333"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:eee"))
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:444"))
|
||||
end
|
||||
end
|
||||
|
||||
context "on approval" do
|
||||
setup do
|
||||
@script = %q(
|
||||
|
@ -75,19 +75,6 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "#update_notice" do
|
||||
setup do
|
||||
@mock_redis = MockRedis.new
|
||||
@forum_topic = FactoryBot.create(:forum_topic)
|
||||
TagChangeNoticeService.stubs(:redis_client).returns(@mock_redis)
|
||||
end
|
||||
|
||||
should "update redis" do
|
||||
FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", forum_topic: @forum_topic)
|
||||
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:aaa"))
|
||||
end
|
||||
end
|
||||
|
||||
should "ignore pending implications when building descendant names" do
|
||||
ti2 = FactoryBot.build(:tag_implication, :antecedent_name => "b", :consequent_name => "c", :status => "pending")
|
||||
ti2.save
|
||||
|
Loading…
Reference in New Issue
Block a user