A platform for community discussion. Free, open, simple.
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)
Roman Rizzidf43ac901d20
diff --git a/app/models/post_timing.rb b/app/models/post_timing.rbindex 96ee2f1782e..1bf1c3f4149 100644--- a/app/models/post_timing.rb+++ b/app/models/post_timing.rb@@ -31,12 +31,14 @@ class PostTiming < ActiveRecord::Baseenddef 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, :msecsON CONFLICT DO NOTHING",args)+# 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+ return if row_count == 0Post.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'end