FIX: Dismiss new with better migration (#12062)

Original PR was reverted because of broken migration https://github.com/discourse/discourse/pull/12058

I fixed it by adding this line
```
          AND topics.id IN(SELECT id FROM topics ORDER BY created_at DESC LIMIT :max_new_topics)
```

This time it is left joining a limited amount of topics. I tested it on few databases and it worked quite smooth
This commit is contained in:
Krzysztof Kotlarek
2021-02-15 08:50:33 +11:00
committed by GitHub
parent 7fe5368718
commit ad3ec5809f
13 changed files with 92 additions and 93 deletions
+3 -1
View File
@@ -8,6 +8,7 @@ class DismissTopics
def perform!
DismissedTopicUser.insert_all(rows) if rows.present?
@rows.map { |row| row[:topic_id] }
end
private
@@ -17,6 +18,7 @@ class DismissTopics
.joins("LEFT JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{@user.id}")
.where("topics.created_at >= ?", since_date)
.where("topic_users.id IS NULL")
.where("topics.archetype <> ?", Archetype.private_message)
.order("topics.created_at DESC")
.limit(SiteSetting.max_new_topics).map do |topic|
{
@@ -38,6 +40,6 @@ class DismissTopics
else
new_topic_duration_minutes.minutes.ago
end
[setting_date, @user.user_stat.new_since, Time.at(SiteSetting.min_new_topics_time).to_datetime].max
[setting_date, @user.created_at, Time.at(SiteSetting.min_new_topics_time).to_datetime].max
end
end
+2
View File
@@ -266,6 +266,8 @@ class UserMerger
update_user_id(:draft_sequences, conditions: "x.draft_key = y.draft_key")
update_user_id(:drafts, conditions: "x.draft_key = y.draft_key")
update_user_id(:dismissed_topic_users, conditions: "x.topic_id = y.topic_id")
EmailLog.where(user_id: @source_user.id).update_all(user_id: @target_user.id)
GroupHistory.where(acting_user_id: @source_user.id).update_all(acting_user_id: @target_user.id)