• Andreas Brandl's avatar
    Perform two-step Routable lookup by path · 739d6a5a
    Andreas Brandl authored
    In order to lookup a Project or Namespace by path, we prefer an exact
    match (case-sensitive) but in absence of that, we'd also take a
    case-insensitive match.
    
    The case-insensitive matching with preference for the exact match is a
    bit more involved in SQL as the exact lookup. Yet, the majority of cases
    will be an exact match. The thinking here is that we can optimize the
    lookup by performing an exact match first and only if there is no
    result, we perform the case-insensitive lookup.
    
    Data for GitLab.com:
    * We have about 15M records in routes table
    * About 2,500 routes exist where there's more than one record
      with the same `lower(path)`
    
    It is possible for a user to craft requests that would always trigger
    the 2-step search (e.g. we have a route for `/foo/bar`, the request is
    always for `/FOO/bar`). In this case, the change at hand is not
    beneficial as it would run an additional query.
    
    However, based on the data, it is highly likely that the vast majority
    of requests can be satisfied with an exact match only.
    
    The context for this change is
    https://gitlab.com/gitlab-org/gitlab-ce/issues/64590#note_208156463.
    739d6a5a
routable.rb 3.15 KB