Maven VReg: Update group stats when creating/destroying cached responses

Context

In the world of Maven virtual registry MVC (API only interactions) (&14137 - closed), VirtualRegistries::Packages::Maven::CachedResponse holds a response from an upstream. This response is cached in GitLab and has a file that's stored in the Object Storage.

The cached responses creation and destruction should update the dependency_proxy_size statistic on the parent group, because cached responses are stored in the dependency proxy bucket.

What does this MR do and why?

  • Update VirtualRegistries::Packages::Maven::CachedResponse model to trigger Groups::UpdateStatisticsWorker whenever a cached response is created/updated/deleted.
  • Update NamespaceStatistics model to take into account the sum of the size of its cached_responses when calculating dependency_proxy_size.
  • Add related specs.

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Make sure the rails-background-jobs service is up & running in your GDK, and open rails console:

root_group = Group.all.detect(&:root?)

r = ::VirtualRegistries::Packages::Maven::Registry.create!(group: root_group)
u = ::VirtualRegistries::Packages::Maven::Upstream.create!(group: root_group, url: 'https://repo1.maven.org/maven2')
VirtualRegistries::Packages::Maven::RegistryUpstream.create!(group: root_group, registry: r, upstream: u)

# create a cached response
cr = VirtualRegistries::Packages::Maven::CachedResponse.create!(group: root_group, upstream: u, size: 2398, file: Tempfile.new('33'), relative_path: "/path/to/file.txt")

# check the `namespace_statistics` of the group, the `dependency_proxy_size` attribute should be 2398 or more (if there are any other depencdency proxy files included in the calculation)
root_group.namespace_statistics

# check the `root_storage_statistics` of the group, also the `dependency_proxy_size` attribute should be updated
root_group.root_storage_statistics

# delete the cached_reponse and then check if the stats is updated
cr.destroy!
root_group.namespace_statistics
root_group.root_storage_statistics

Related to #482493 (closed)

Edited by Moaz Khalifa

Merge request reports

Loading