mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 21:09:11 +08:00
FIX: Set last_read_post_number for imported watching topic users (#32229)
Ensure `last_read_post_number` is set to the latest post for imported topic users with a `watching` notification level, even if they haven't engaged with the topic
This commit is contained in:
parent
181606e0bd
commit
9bfb4c005d
@ -1378,6 +1378,27 @@ class BulkImport::Generic < BulkImport::Base
|
||||
liked = excluded.liked
|
||||
SQL
|
||||
|
||||
DB.exec(<<~SQL, notification_level: NotificationLevels.topic_levels[:watching])
|
||||
WITH
|
||||
latest_posts AS (
|
||||
SELECT p.topic_id, MAX(p.post_number) AS number
|
||||
FROM posts p
|
||||
WHERE p.deleted_at IS NULL
|
||||
AND NOT p.hidden
|
||||
AND p.user_id > 0
|
||||
GROUP BY p.topic_id
|
||||
)
|
||||
UPDATE topic_users tu
|
||||
SET last_read_post_number = latest_posts.number
|
||||
FROM latest_posts
|
||||
JOIN topics t ON t.id = latest_posts.topic_id
|
||||
WHERE tu.topic_id = latest_posts.topic_id
|
||||
AND tu.notification_level = :notification_level
|
||||
AND tu.last_read_post_number IS NULL
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.visible
|
||||
SQL
|
||||
|
||||
puts " Updated topic users in #{(Time.now - start_time).to_i} seconds."
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user