diff --git a/app/jobs/scheduled/ensure_db_consistency.rb b/app/jobs/scheduled/ensure_db_consistency.rb index d04b30f3c71..83896fb2773 100644 --- a/app/jobs/scheduled/ensure_db_consistency.rb +++ b/app/jobs/scheduled/ensure_db_consistency.rb @@ -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! diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index 1816f34cbe1..e2c4bdff667 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -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 < 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