FIX: do not insert conflict rows into category user

This could fail under certain race conditions
This commit is contained in:
Sam Saffron 2019-11-19 12:23:11 +11:00
parent 93d7abe372
commit f49ef851df
1 changed files with 3 additions and 1 deletions

View File

@ -15,7 +15,8 @@ class RemoveSuppressFromLatestFromCategory < ActiveRecord::Migration[6.0]
# We shouldn't encourage to have more than 10 categories in `default_categories_muted` site setting.
if ids.count <= 10
DB.exec(<<~SQL, muted: CategoryUser.notification_levels[:muted])
# CategoryUser.notification_levels[:muted] is 0, avoid reaching to object model
DB.exec(<<~SQL, muted: 0)
INSERT INTO category_users (category_id, user_id, notification_level)
SELECT c.id category_id, u.id user_id, :muted
FROM users u
@ -25,6 +26,7 @@ class RemoveSuppressFromLatestFromCategory < ActiveRecord::Migration[6.0]
AND c.id = cu.category_id
WHERE c.suppress_from_latest = TRUE
AND cu.notification_level IS NULL
ON CONFLICT DO NOTHING
SQL
DB.exec(<<~SQL, value: ids.join("|"))