Implement targeted message deletion via background job

What does this MR do and why?

This MR moves the targeted message deletion from a synchronous operation to an asynchronous background job.

Closes: #581579

Related sql:

Query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46312/commands/141359

DELETE FROM targeted_messages WHERE id = <id>

Query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46312/commands/141364

DELETE FROM "targeted_message_dismissals" 
WHERE "id" IN (
  SELECT "id" FROM "targeted_message_dismissals" 
  WHERE "targeted_message_dismissals"."targeted_message_id" = 1 
  ORDER BY "targeted_message_dismissals"."id" ASC 
  LIMIT 1000
)

Query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46367/commands/141454

DELETE FROM "targeted_message_namespaces" 
WHERE "id" IN (
  SELECT "id" FROM "targeted_message_namespaces" 
  WHERE "targeted_message_namespaces"."targeted_message_id" = 1 
  ORDER BY "targeted_message_namespaces"."id" ASC 
  LIMIT 1000
)

References

Screenshots or screen recordings

This is a bad tophat, but the changes work with the background deletes.

Before After
Screenshot_2025-11-26_at_11.44.34_PM Screenshot_2025-12-01_at_11.09.35_AM

How to set up and validate locally

Example:

  1. Simulate SaaS: https://docs.gitlab.com/development/ee_features/#simulate-a-saas-instance
  2. In rails console, run the following:
    Feature.enable(:targeted_messages_admin_ui)
    namespace1 = Namespace.first
    namespace2 = Namespace.second
    Notifications::TargetedMessage.create!(
     target_type: :banner_page_level,
     namespaces: [namespace1, namespace2]
    )
  3. Visit localhost:3000/admin/targeted_messages and you will see a targeted_message existing
  4. Delete the message and you will see a banner. -->

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #581579!

Edited by Roy Liu

Merge request reports

Loading