Cache database repository objects for API requests
Context
In #449 (closed) we observed that repositoryStore.FindByPath
and repositoryStore.CreateOrFindByPath
are mildly expensive operations, and since repository scoped requests only deal with a single repository, we should avoid instantiating this repository object more than once.
Solutions
Pass via the Context
Instantiating this object before the handlers and passing it along via the context would discourage extra calls to repositoryStore.FindByPath
https://gitlab.com/gitlab-org/container-registry/-/blob/master/registry/handlers/app.go#L976, but sometimes we'll wish to create the repository if it doesn't exist, and other times we need to error out if it does not exist.
Create a memoized repository store
Saving the result of repositoryStore.FindByPath
and repositoryStore.CreateOrFindByPath
allows us to only make the call once per request, while allowing us to continue using the previous logic in the callers.