Caching _namespace_storage_limit_alert.html.haml
app/views/shared/_namespace_storage_limit_alert.html.haml
is loaded on most "repository" views. Currently it performs at least one, sometimes two queries similar to the following, which have a small but constant performance impact (~60ms in queries) on pages underneath a namespace with a large number of repositories (e.g. gitlab-org/
):
SELECT SUM((("project_statistics"."repository_size" + "project_statistics"."lfs_objects_size") - 10737418240)) FROM "projects" INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project' INNER JOIN "project_statistics" ON "project_statistics"."project_id" = "projects"."id" WHERE (rs.path LIKE 'gitlab-org/%') AND ("project_statistics"."repository_size" + "project_statistics"."lfs_objects_size") > 10737418240 AND "projects"."repository_size_limit" IS NULL
Explain: https://explain.depesz.com/s/bOOd
This view should be cachable, but we need to scope the cache key based on the following:
- Changes to the file size limit by an admin
- Changes to the quota by a user purchasing more storage
- Updates to the files in the repository
Currently I'm trying to verify if there are existing cache keys which will be updated when these areas are updated. Ideally namespace.updated_at
should be touched under these conditions.
Edited by Robert May