Don't get full set of refs from cache when using ExtractsRef
Getting all the refs for a project is slow: https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/124
We get all the refs every time you load a page that uses ExtractsRef. That's any page where we have a ref followed by a path, like master/Gemfile
- is that showing the tree of the master/Gemfile
ref, or the Gemfile
path on the master
ref? ExtractsRef appears to be the most common use for Repository#ref_names
, which will fetch all branch and tag names.
For instance, on https://gitlab.com/gitlab-org/gitlab/-/blob/master/Gemfile, we spend around 60 ms getting the members of the tag and branch name caches. For Redis, that's an eternity!
Some ideas to consider:
- We already cache the default branch, so we could assume that we're using that? However, we take the longest match, so this could break if you have (say)
main
andmain/foo
. - If we know that a repository has no ambiguous refs (one ref is a prefix of another), we could consider caching that. And then we'd only need a few SISMEMBER calls instead.