Update namespace statistics when a project is deleted
What does this MR do and why?
Update namespace statistics when a project is deleted.
When a project is deleted, its dependent records that uses storage are also deleted (e.g job artifacts, pipeline artifacts, packages, etc).
Usually, changes to these records would trigger an update on project statistics and eventually namespace statistics through ProjectStatistics.increment_statistic
and FlushCounterIncrementsWorker
.
However, when the project is deleted, FlushCounterIncrementsWorker
would not do anything because the record has been deleted. As a result, it does not execute the counter_attribute_after_flush
callback and the Namespaces::ScheduleAggregationWorker
.
To address this problem, when a project is deleted, we publishes a ProjectDeletedEvent
to the event store. A Namespaces::RefreshStatisticsWorker
is subscribed to this event, which then refreshes the namespace statistics.
Screenshots or screen recordings
How to set up and validate locally
- Create a group
group-1
- Create a project in
group-1
,group-1/project-1
- Create another project in
group-1
,group-1/project-2
- In both projects, run a CI pipeline to create artifacts. An example CI job can be found below.
- Wait until
group-1
usage quota (Settings > Usage Quota) is updated to include all build artifacts from both projects. - Delete
project-2
. - View
group-1
usage quota and verify that the usage no longer includesproject-2
usage.
Example CI (creates ~23.84 MiB of artifact per pipeline):
test:
parallel: 5
script:
- head -c 5000000 /dev/urandom > foo.txt
artifacts:
paths:
- foo.txt
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #342049 (closed)