mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
FIX: Decrement posts read count when destroying post timings (#8172)
This commit is contained in:
parent
349c1cd085
commit
b805037825
@ -71,6 +71,8 @@ class PostTiming < ActiveRecord::Base
|
||||
last_read_post_number: last_read
|
||||
)
|
||||
|
||||
topic.posts.find_by(post_number: post_number).decrement!(:reads)
|
||||
|
||||
if !topic.private_message?
|
||||
set_minimum_first_unread!(user_id: user.id, date: topic.updated_at)
|
||||
end
|
||||
@ -87,6 +89,8 @@ class PostTiming < ActiveRecord::Base
|
||||
.where('user_id = ? and topic_id in (?)', user_id, topic_ids)
|
||||
.delete_all
|
||||
|
||||
Post.where(topic_id: topic_ids).update_all('reads = reads - 1')
|
||||
|
||||
date = Topic.listable_topics.where(id: topic_ids).minimum(:updated_at)
|
||||
|
||||
if date
|
||||
|
@ -164,4 +164,24 @@ describe PostTiming do
|
||||
|
||||
end
|
||||
|
||||
describe 'decrementing posts read count when destroying post timings' do
|
||||
let(:initial_read_count) { 0 }
|
||||
let(:post) { Fabricate(:post, reads: initial_read_count) }
|
||||
|
||||
before do
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
||||
end
|
||||
|
||||
it '#destroy_last_for decrements the reads count for a post' do
|
||||
PostTiming.destroy_last_for(post.user, post.topic_id)
|
||||
|
||||
expect(post.reload.reads).to eq initial_read_count
|
||||
end
|
||||
|
||||
it '#destroy_for decrements the reads count for a post' do
|
||||
PostTiming.destroy_for(post.user, [post.topic_id])
|
||||
|
||||
expect(post.reload.reads).to eq initial_read_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user