jobs: drop favgroup expunge job.

Make `Post#expunge!` remove favgroups synchronously.
This commit is contained in:
evazion
2019-08-16 20:49:34 -05:00
parent 798d524e60
commit 817f5ecf9c
3 changed files with 10 additions and 8 deletions

View File

@@ -178,13 +178,6 @@ class FavoriteGroup < ApplicationRecord
end
end
def self.purge_post(post_id)
post_id = post_id.id if post_id.is_a?(Post)
for_post(post_id).find_each do |group|
group.remove!(post_id)
end
end
def remove!(post_id)
with_lock do
post_id = post_id.id if post_id.is_a?(Post)

View File

@@ -1000,7 +1000,9 @@ class Post < ApplicationRecord
end
def remove_from_fav_groups
FavoriteGroup.delay.purge_post(id)
FavoriteGroup.for_post(id).find_each do |favgroup|
favgroup.remove!(id)
end
end
end

View File

@@ -41,6 +41,7 @@ class PostTest < ActiveSupport::TestCase
@upload = UploadService.new(FactoryBot.attributes_for(:jpg_upload)).start!
@post = @upload.post
Favorite.add(post: @post, user: @user)
create(:favorite_group).add!(@post.id)
end
teardown do
@@ -63,6 +64,12 @@ class PostTest < ActiveSupport::TestCase
assert_equal(0, Favorite.for_user(@user.id).where("post_id = ?", @post.id).count)
end
should "remove all favgroups" do
assert_equal(1, FavoriteGroup.for_post(@post.id).count)
@post.expunge!
assert_equal(0, FavoriteGroup.for_post(@post.id).count)
end
should "decrement the uploader's upload count" do
assert_difference("@post.uploader.reload.post_upload_count", -1) do
@post.expunge!