Reset notification email to default when used email got deleted

What does this MR do and why?

Reset notification email to default when used email got deleted.

Fixes #438600 (closed).

How to set up and validate locally

database query plan

  1. The where().each_batch() call results in SELECT queries like these:
SELECT
    "notification_settings"."id"
FROM
    "notification_settings"
WHERE
    "notification_settings"."user_id" = 1
    AND "notification_settings"."notification_email" = 'aaa@bbb.ccc'
ORDER BY
    "notification_settings"."id" ASC
LIMIT 1

👉 https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30948/commands/96122

SELECT
    "notification_settings"."id"
FROM
    "notification_settings"
WHERE
    "notification_settings"."user_id" = 1
    AND "notification_settings"."notification_email" = 'aaa@bbb.ccc'
    AND "notification_settings"."id" >= 1
ORDER BY
    "notification_settings"."id" ASC
LIMIT 1 OFFSET 500

👉 https://postgres.ai/console/gitlab/gitlab-production-main/sessions/30948/commands/96123

  1. And the update_all then updates each batch in bulk
UPDATE
    "notification_settings"
SET
    "notification_email" = NULL
WHERE
    "notification_settings"."user_id" = 1
    AND "notification_settings"."notification_email" = 'aaa@bbb.ccc'
    AND "notification_settings"."id" >= 1

👉 https://postgres.ai/console/gitlab/gitlab-production-main/sessions/30948/commands/96124

All 3 query plans recommend adding a specialised index (email+user), which is part of this MR now.

Edited by Thomas Hutterer

Merge request reports

Loading