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:
- Add
for_projectscope that applies the following condition:(target_type = 'Project') OR (target_type IS NULL AND action IN (<project_actions>) AND project_id IS NOT NULL)
- Override the
EventsFinderto use thefor_projectscope when filtering fortarget_type=project. - Override the
event.target_typeandevent.target_idgetter to returnProjectandproject_idrespectively 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 |
|
|
left |
|
|
joined |
|
|
created |
|
|
How to set up and validate locally
backend validation:
- On the master branch, go to https://gdk.test:3000/api/v4/events?target_type=project, and not all project events are listed.
- Now, checkout this branch and go to the above link again, and many more project events would be listed.
frontend validation:
- Go to
Project > Manage > ActivityorGroup > Manage > Activitypage. - Ensure that all project related events are rendered correctly (
created,leave,joined,expired).- For the
expiredevent, you can simulate this by updating theactionvalue of aleaveevent in the Rails console or PSQL.
- For the
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







