mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: We don't want to update the post read count and user stats if the post timing wasn't created due to a conflict. (#8824)
This commit is contained in:
parent
73b04976e5
commit
df43ac901d
1 changed files with 3 additions and 1 deletions
|
@ -31,12 +31,14 @@ class PostTiming < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.record_new_timing(args)
|
def self.record_new_timing(args)
|
||||||
DB.exec("INSERT INTO post_timings (topic_id, user_id, post_number, msecs)
|
row_count = DB.exec("INSERT INTO post_timings (topic_id, user_id, post_number, msecs)
|
||||||
SELECT :topic_id, :user_id, :post_number, :msecs
|
SELECT :topic_id, :user_id, :post_number, :msecs
|
||||||
ON CONFLICT DO NOTHING",
|
ON CONFLICT DO NOTHING",
|
||||||
args)
|
args)
|
||||||
|
|
||||||
# concurrency is hard, we are not running serialized so this can possibly
|
# concurrency is hard, we are not running serialized so this can possibly
|
||||||
# still happen, if it happens we just don't care, its an invalid record anyway
|
# still happen, if it happens we just don't care, its an invalid record anyway
|
||||||
|
return if row_count == 0
|
||||||
Post.where(['topic_id = :topic_id and post_number = :post_number', args]).update_all 'reads = reads + 1'
|
Post.where(['topic_id = :topic_id and post_number = :post_number', args]).update_all 'reads = reads + 1'
|
||||||
UserStat.where(user_id: args[:user_id]).update_all 'posts_read_count = posts_read_count + 1'
|
UserStat.where(user_id: args[:user_id]).update_all 'posts_read_count = posts_read_count + 1'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue