This commit is contained in:
r888888888
2017-11-16 12:00:54 -08:00
parent 2c620f205b
commit 2e0534a66b
4 changed files with 29 additions and 4 deletions

View File

@@ -43,8 +43,12 @@ class AliasAndImplicationImporter
elsif line =~ /^(?:mass update|updating|update|change) (.+?) -> (.*)$/i
[:mass_update, $1, $2]
elsif line =~ /^category (\S+) -> (#{Tag.categories.regexp})/
[:change_category, $1, $2]
elsif line.strip.empty?
# do nothing
else
raise "Unparseable line: #{line}"
end
@@ -66,7 +70,7 @@ class AliasAndImplicationImporter
raise "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
end
when :remove_alias, :remove_implication, :mass_update
when :remove_alias, :remove_implication, :mass_update, :change_category
# okay
else
@@ -107,7 +111,13 @@ private
tag_implication.destroy
when :mass_update
Delayed::Job.enqueue(Moderator::TagBatchChange.new(token[1], token[2], CurrentUser.user, CurrentUser.ip_addr), :queue => "default")
Delayed::Job.enqueue(Moderator::TagBatchChange.new(token[1], token[2], CurrentUser.id, CurrentUser.ip_addr), :queue => "default")
when :change_category
tag = Tag.find_by_name(token[1])
tag.category = Tag.categories.value_for(token[2])
tag.save
tag.update_category_cache_for_all
else
raise "Unknown token: #{token[0]}"

View File

@@ -149,7 +149,7 @@ class Tag < ApplicationRecord
end
def update_category_cache
Cache.put("tc:#{Cache.hash(name)}", category, 1.hour)
Cache.put("tc:#{Cache.hash(name)}", category, 3.hours)
end
end
@@ -221,7 +221,7 @@ class Tag < ApplicationRecord
# next few lines if the category is changed.
tag.update_category_cache
if category_id != tag.category && !tag.is_locked? && (CurrentUser.is_builder? || tag.post_count <= 50)
if category_id != tag.category && !tag.is_locked? && ((CurrentUser.is_builder? && tag.post_count < 10_000) || tag.post_count <= 50)
tag.update_column(:category, category_id)
tag.update_category_cache_for_all
end

View File

@@ -12,6 +12,7 @@ unimply aaa -> bbb
alias aaa -> bbb
imply aaa -> bbb
update aaa -> bbb
category tag_name -> category_name
</pre>
<%= text_area :bulk_update_request, :script, :size => "50x10" %>
</div>

View File

@@ -12,6 +12,20 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "category command" do
setup do
@tag = Tag.find_or_create_by_name("hello")
@list = "category hello -> artist\n"
@importer = AliasAndImplicationImporter.new(@list, nil)
end
should "work" do
@importer.process!
@tag.reload
assert_equal(Tag.categories.value_for("artist"), @tag.category)
end
end
context "given a valid list" do
setup do
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"