expunge: decrement upload and note/post update counts (fix #2062).
This commit is contained in:
@@ -147,8 +147,6 @@ class Note < ApplicationRecord
|
|||||||
|
|
||||||
def create_version
|
def create_version
|
||||||
return unless versioned_attributes_changed?
|
return unless versioned_attributes_changed?
|
||||||
User.where(id: CurrentUser.id).update_all("note_update_count = note_update_count + 1")
|
|
||||||
CurrentUser.reload
|
|
||||||
|
|
||||||
if merge_version?
|
if merge_version?
|
||||||
merge_version
|
merge_version
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class NoteVersion < ApplicationRecord
|
class NoteVersion < ApplicationRecord
|
||||||
before_validation :initialize_updater
|
before_validation :initialize_updater
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User", :counter_cache => "note_update_count"
|
||||||
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
|
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
|
||||||
attr_accessible :note_id, :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id, :version
|
attr_accessible :note_id, :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id, :version
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
belongs_to :approver, :class_name => "User"
|
belongs_to :approver, :class_name => "User"
|
||||||
belongs_to :uploader, :class_name => "User"
|
belongs_to :uploader, :class_name => "User", :counter_cache => "post_upload_count"
|
||||||
belongs_to :parent, :class_name => "Post"
|
belongs_to :parent, :class_name => "Post"
|
||||||
has_one :upload, :dependent => :destroy
|
has_one :upload, :dependent => :destroy
|
||||||
has_one :artist_commentary, :dependent => :destroy
|
has_one :artist_commentary, :dependent => :destroy
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class PostArchive < ApplicationRecord
|
|||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :updater, class_name: "User"
|
belongs_to :updater, class_name: "User", counter_cache: "post_update_count"
|
||||||
|
|
||||||
def self.enabled?
|
def self.enabled?
|
||||||
Danbooru.config.aws_sqs_archives_url.present?
|
Danbooru.config.aws_sqs_archives_url.present?
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ class Upload < ApplicationRecord
|
|||||||
post = convert_to_post
|
post = convert_to_post
|
||||||
post.distribute_files
|
post.distribute_files
|
||||||
if post.save
|
if post.save
|
||||||
User.where(id: CurrentUser.id).update_all("post_upload_count = post_upload_count + 1")
|
|
||||||
create_artist_commentary(post) if include_artist_commentary?
|
create_artist_commentary(post) if include_artist_commentary?
|
||||||
ugoira_service.save_frame_data(post) if is_ugoira?
|
ugoira_service.save_frame_data(post) if is_ugoira?
|
||||||
notify_cropper(post)
|
notify_cropper(post)
|
||||||
|
|||||||
@@ -61,6 +61,25 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(0, Favorite.for_user(@user.id).where("post_id = ?", @post.id).count)
|
assert_equal(0, Favorite.for_user(@user.id).where("post_id = ?", @post.id).count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "decrement the uploader's upload count" do
|
||||||
|
assert_difference("@post.uploader.reload.post_upload_count", -1) do
|
||||||
|
@post.expunge!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "decrement the user's note update count" do
|
||||||
|
FactoryGirl.create(:note, post: @post)
|
||||||
|
assert_difference(["@post.uploader.reload.note_update_count"], -1) do
|
||||||
|
@post.expunge!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "decrement the user's post update count" do
|
||||||
|
assert_difference(["@post.uploader.reload.post_update_count"], -1) do
|
||||||
|
@post.expunge!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "remove the post from iqdb" do
|
should "remove the post from iqdb" do
|
||||||
mock_iqdb_service!
|
mock_iqdb_service!
|
||||||
Post.iqdb_sqs_service.expects(:send_message).with("remove\n#{@post.id}")
|
Post.iqdb_sqs_service.expects(:send_message).with("remove\n#{@post.id}")
|
||||||
@@ -1162,11 +1181,13 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
should "increment the updater's post_update_count" do
|
should "increment the updater's post_update_count" do
|
||||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
CurrentUser.reload
|
|
||||||
|
|
||||||
assert_difference("CurrentUser.post_update_count", 1) do
|
# XXX in the test environment the update count gets bumped twice: and
|
||||||
|
# once by Post#post_update_count, and once by the counter cache. in
|
||||||
|
# production the counter cache doesn't bump the count, because
|
||||||
|
# versions are created on a separate server.
|
||||||
|
assert_difference("CurrentUser.user.reload.post_update_count", 2) do
|
||||||
post.update_attributes(:tag_string => "zzz")
|
post.update_attributes(:tag_string => "zzz")
|
||||||
CurrentUser.reload
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user