• Sean McGivern's avatar
    Optimise happy-path lookup for refs without slashes · 04a5b342
    Sean McGivern authored
    Fetching all references for a repository uses SMEMBERS, which can be
    quite slow. We need to fetch all references to resolve ambiguities in
    certain edge cases. However, most references do not contain a slash, and
    most repositories do not contain ambiguous references (where a tag is a
    prefix of a branch or vice versa).
    
    In those cases, we can trade two slow-ish Redis calls (SMEMBERS to get
    all tags and branches) for a maximum of four much faster Redis calls,
    because they are all GETs:
    
    1. One for the feature flag (which will go away in future hopefully).
    2. One to check if the repository has ambiguous refs.
    3. One for checking membership of branch names.
    4. One for checking membership of tag names (only if we didn't match a
       branch).
    
    In the worst case - when the repository does not contain ambiguous refs
    - we add those calls to the existing calls, but this should still not be
    a huge amount of overhead in that case.
    
    When the feature flag is disabled (which is the default), we're just
    adding a single GET.
    04a5b342
path_extraction_shared_examples.rb 5.58 KB