Merge pull request #4044 from r888888888/tag-change-notices
Tag change notices
This commit is contained in:
@@ -147,6 +147,10 @@ module PostsHelper
|
||||
return params[:pool_id].to_i == pool.id
|
||||
end
|
||||
|
||||
def show_tag_change_notice?
|
||||
Tag.scan_query(params[:tags]).size == 1 && TagChangeNoticeService.get_forum_topic_id(params[:tags])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nav_params_for(page)
|
||||
|
||||
@@ -100,6 +100,30 @@ 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
|
||||
|
||||
def parse(tokens, approver)
|
||||
|
||||
18
app/logical/tag_change_notice_service.rb
Normal file
18
app/logical/tag_change_notice_service.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module TagChangeNoticeService
|
||||
extend self
|
||||
|
||||
def redis_client
|
||||
::Redis.new(url: Danbooru.config.redis_url)
|
||||
end
|
||||
|
||||
def get_forum_topic_id(tag)
|
||||
redis_client.get("tcn:#{tag}")
|
||||
end
|
||||
|
||||
def update_cache(affected_tags, forum_topic_id)
|
||||
rc = redis_client
|
||||
affected_tags.each do |tag|
|
||||
rc.setex("tcn:#{tag}", 1.week, forum_topic_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,6 +16,7 @@ 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")}
|
||||
@@ -241,4 +242,11 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
def estimate_update_count
|
||||
AliasAndImplicationImporter.new(script, nil).estimate_update_count
|
||||
end
|
||||
|
||||
def update_notice
|
||||
TagChangeNoticeService.update_cache(
|
||||
AliasAndImplicationImporter.new(script, nil).affected_tags,
|
||||
forum_topic_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,6 +32,7 @@ class TagRelationship < ApplicationRecord
|
||||
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
|
||||
validates :forum_topic, presence: { message: "must exist" }, if: -> { forum_topic_id.present? }
|
||||
validate :antecedent_and_consequent_are_different
|
||||
after_save :update_notice
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
@@ -204,6 +205,13 @@ 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
|
||||
|
||||
extend SearchMethods
|
||||
include MessageMethods
|
||||
end
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
</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 %>
|
||||
|
||||
Reference in New Issue
Block a user