Skip to content

Fix Events API Project target_type filtering for NULL values

What does this MR do and why?

Update the Events API target_type filter to include legacy project events with missing target_type. Specifically this MR does the following:

  1. Add for_project scope that applies the following condition:
    • (target_type = 'Project') OR (target_type IS NULL AND action IN (<project_actions>) AND project_id IS NOT NULL)
  2. Override the EventsFinder to use the for_project scope when filtering for target_type=project.
  3. Override the event.target_type and event.target_id getter to return Project and project_id respectively for legacy project events.

References

Another approach would be to backfill all the events where target_type is nil, but this would require backfilling 2.5B records. Ref &19098.

Related to #570193 (closed)

Query plans

Before After
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/44443/commands/136225 https://console.postgres.ai/gitlab/gitlab-production-main/sessions/44537/commands/136781

Screenshots

Action Project log Group log
expired image image
left image image
joined image image
created image image

How to set up and validate locally

backend validation:

  1. On the master branch, go to https://gdk.test:3000/api/v4/events?target_type=project, and not all project events are listed.
  2. Now, checkout this branch and go to the above link again, and many more project events would be listed.

frontend validation:

  1. Go to Project > Manage > Activity or Group > Manage > Activity page.
  2. Ensure that all project related events are rendered correctly (created, leave, joined, expired).
    • For the expired event, you can simulate this by updating the action value of a leave event in the Rails console or PSQL.

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.

Edited by Shane Maglangit

Merge request reports

Loading