BURs: update posts in parallel.
When processing an alias, rename, implication, mass update, or nuke, update the posts in parallel. This means that if we alias foo to bar, for example, then we use four processes at once to retag the posts from foo to bar. This doesn't mean that if we have two aliases in a BUR, we process both aliases in parallel. It simply means that when processing an alias, we update the posts in parallel for that alias.
This commit is contained in:
@@ -21,4 +21,28 @@ class ApplicationRecordTest < ActiveSupport::TestCase
|
||||
assert_equal(@tags.reverse, Tag.search(updated_at: ">=#{@tags.first.updated_at}"))
|
||||
end
|
||||
end
|
||||
|
||||
context "ApplicationRecord#parallel_each" do
|
||||
context "in threaded mode" do
|
||||
should "set CurrentUser correctly" do
|
||||
@user1 = create(:user)
|
||||
@user2 = create(:user)
|
||||
|
||||
CurrentUser.scoped(@user1, "1.1.1.1") do
|
||||
Tag.parallel_each do |tag|
|
||||
assert_equal(@user1, CurrentUser.user)
|
||||
assert_equal("1.1.1.1", CurrentUser.ip_addr)
|
||||
|
||||
CurrentUser.scoped(@user2, "2.2.2.2") do
|
||||
assert_equal(@user2, CurrentUser.user)
|
||||
assert_equal("2.2.2.2", CurrentUser.ip_addr)
|
||||
end
|
||||
|
||||
assert_equal(@user1, CurrentUser.user)
|
||||
assert_equal("1.1.1.1", CurrentUser.ip_addr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -266,6 +266,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
should "update the tags" do
|
||||
assert_equal("bar", @post.reload.tag_string)
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
assert_equal(User.system, @post.versions.last.updater)
|
||||
end
|
||||
|
||||
should "be case-sensitive" do
|
||||
@@ -288,6 +289,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
should "rename the tags" do
|
||||
assert_equal("bar blah", @post.reload.tag_string)
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
assert_equal(User.system, @post.versions.last.updater)
|
||||
end
|
||||
|
||||
should "move the tag's artist entry and wiki page" do
|
||||
@@ -351,6 +353,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("foo", @post.reload.tag_string)
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
assert_equal(User.system, @post.versions.last.updater)
|
||||
end
|
||||
|
||||
should "remove implications" do
|
||||
@@ -370,6 +373,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal([], @pool.post_ids)
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
assert_equal(User.system, @pool.versions.last.updater)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -514,6 +518,10 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
end
|
||||
|
||||
should "update the post as DanbooruBot" do
|
||||
assert_equal(User.system, @post.versions.last.updater)
|
||||
end
|
||||
|
||||
should "set the BUR as failed if there is an unexpected error during processing" do
|
||||
@bur = create(:bulk_update_request, script: "alias one -> two")
|
||||
TagAlias.any_instance.stubs(:process!).raises(RuntimeError.new("oh no"))
|
||||
|
||||
@@ -142,6 +142,8 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("bbb ccc", post1.reload.tag_string)
|
||||
assert_equal("ccc ddd", post2.reload.tag_string)
|
||||
assert_equal(User.system, post1.versions.last.updater)
|
||||
assert_equal(CurrentUser.user, post2.versions.last.updater)
|
||||
end
|
||||
|
||||
should "not validate for transitive relations" do
|
||||
|
||||
@@ -124,6 +124,8 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("sword weapon", p1.reload.tag_string)
|
||||
assert_equal("sword weapon", p2.reload.tag_string)
|
||||
assert_equal(User.system, p1.versions.last.updater)
|
||||
assert_equal(CurrentUser.user, p2.versions.last.updater)
|
||||
end
|
||||
|
||||
context "when calculating implied tags" do
|
||||
|
||||
Reference in New Issue
Block a user