forked from e621ng/e621ng
fixes #2229
This commit is contained in:
parent
5063e326e3
commit
8b2b981b80
@ -96,7 +96,14 @@ class ForumTopic < ActiveRecord::Base
|
||||
ForumTopicVisit.create(:user_id => user.id, :forum_topic_id => id, :last_read_at => updated_at)
|
||||
end
|
||||
|
||||
# user.update_attribute(:last';¬≥÷_forum_read_at, ForumTopicVisit.where(:user_id => user.id, :forum_topic_id => id).minimum(:last_read_at) || updated_at)
|
||||
has_unread_topics = ForumTopic.where("forum_topics.updated_at >= ?", user.last_forum_read_at)
|
||||
.joins("left join forum_topic_visits on (forum_topic_visits.forum_topic_id = forum_topics.id and forum_topic_visits.user_id = #{user.id})")
|
||||
.where("(forum_topic_visits.id is null or forum_topic_visits.last_read_at < forum_topics.updated_at)")
|
||||
.exists?
|
||||
unless has_unread_topics
|
||||
user.update_attribute(:last_forum_read_at, Time.now)
|
||||
ForumTopicVisit.prune!(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
class AddUpdatedAtIndexToForumTopics < ActiveRecord::Migration
|
||||
def up
|
||||
execute "set statement_timeout = 0"
|
||||
add_index :forum_topics, :updated_at
|
||||
end
|
||||
|
||||
def down
|
||||
execute "set statement_timeout = 0"
|
||||
remove_index :forum_topics, :updated_at
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user