DEV: Drop user_stats count column constraints (#15949)

We added this constraint in 5bd55acf835e79ba8f8b655c684035c3f2293652
but it is causing problems in hosted sites and is catching the
issue too far down the line. This commit removes the constraint
for now, and also fixes an issue found with PostDestroyer
which wasn't using the UserStatCountUpdater when updating post_count
and thus was causing negative numbers to occur.
This commit is contained in:
Martin Brennan
2022-02-16 11:49:11 +10:00
committed by GitHub
parent 33a0ad1b69
commit f9ec2b90a0
5 changed files with 85 additions and 18 deletions

View File

@ -442,6 +442,21 @@ describe PostDestroyer do
expect(user2.user_stat.post_count).to eq(0)
end
it "does not update post_count or topic_count to a negative number" do
user1 = post.user
reply2 = create_post(topic_id: post.topic_id, user: user1)
expect(user1.user_stat.topic_count).to eq(1)
expect(user1.user_stat.post_count).to eq(1)
user1.user_stat.update!(topic_count: 0)
user1.user_stat.update!(post_count: 0)
PostDestroyer.new(admin, post).destroy
user1.reload
expect(user1.user_stat.topic_count).to eq(0)
expect(user1.user_stat.post_count).to eq(0)
end
it 'deletes the published page associated with the topic' do
slug = 'my-published-page'
publish_result = PublishedPage.publish!(admin, post.topic, slug)