Skip to content

A platform for community discussion. Free, open, simple.

PERF: `PostTiming.pretend_read` to not update `TopicUser` cache columns (#27201)

Alan Guo Xiang Tan3c0e672fc417
diff --git a/app/models/post_timing.rb b/app/models/post_timing.rb
index 6bfc5b7f2bd..3d5c2a0f611 100644
--- a/app/models/post_timing.rb
+++ b/app/models/post_timing.rb
@@ -35,7 +35,7 @@ class PostTiming < ActiveRecord::Base
DB.exec(sql_query, params)
- TopicUser.ensure_consistency!(topic_id)
+ TopicUser.update_last_read_post_number(topic_id:)
end
def self.record_new_timing(args)
diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb
index 9d35a5f8c7d..823f6b28f51 100644
--- a/app/models/topic_user.rb
+++ b/app/models/topic_user.rb
@@ -531,8 +531,11 @@ SQL
end
def self.ensure_consistency!(topic_id = nil)
- update_post_action_cache(topic_id: topic_id)
+ update_post_action_cache(topic_id:)
+ update_last_read_post_number(topic_id:)
+ end
+ def self.update_last_read_post_number(topic_id: nil)
# TODO this needs some reworking, when we mark stuff skipped
# we up these numbers so they are not in-sync
# the simple fix is to add a column here, but table is already quite big