fixes #2229
This commit is contained in:
@@ -96,7 +96,14 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
ForumTopicVisit.create(:user_id => user.id, :forum_topic_id => id, :last_read_at => updated_at)
|
ForumTopicVisit.create(:user_id => user.id, :forum_topic_id => id, :last_read_at => updated_at)
|
||||||
end
|
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
|
||||||
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
|
||||||
Reference in New Issue
Block a user