PERF/FIX: Dismiss Post coming back

Now that post numbers are monotonically increasing we should not need this job
Stuff should just self correct as users browser along

Corrected the job not to reset the disimissed posts in case we need it
This commit is contained in:
Sam 2014-08-11 10:26:46 +10:00
parent 0b5e19303d
commit eeff092ead
2 changed files with 7 additions and 3 deletions

View file

@ -4,7 +4,6 @@ module Jobs
every 12.hours
def execute(args)
TopicUser.ensure_consistency!
UserVisit.ensure_consistency!
Group.refresh_automatic_groups!
Notification.ensure_consistency!

View file

@ -230,10 +230,15 @@ class TopicUser < ActiveRecord::Base
end
def self.ensure_consistency!(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
# long term we want to split up topic_users and allow for this better
builder = SqlBuilder.new <<SQL
UPDATE topic_users t
SET
last_read_post_number = last_read,
last_read_post_number = LEAST(GREATEST(last_read, last_read_post_number), max_post_number),
seen_post_count = LEAST(max_post_number,GREATEST(t.seen_post_count, last_read))
FROM (
SELECT topic_id, user_id, MAX(post_number) last_read
@ -251,7 +256,7 @@ SQL
X.topic_id = t.topic_id AND
X.user_id = t.user_id AND
(
last_read_post_number <> last_read OR
last_read_post_number <> LEAST(GREATEST(last_read, last_read_post_number), max_post_number) OR
seen_post_count <> LEAST(max_post_number,GREATEST(t.seen_post_count, last_read))
)
SQL