Skip to content
  • Yorick Peterse's avatar
    Rewrite SnippetsFinder to improve performance · b81102d2d9a4
    Yorick Peterse authored
    This completely rewrites the SnippetsFinder class from the ground up in
    order to improve its performance. The old code was beyond salvaging. It
    was complex, included various Rails 5 workarounds, comments that
    shouldn't be necessary, and most important of all: it produced a really
    poorly performing database query.
    
    As a result, I opted for rewriting the finder from scratch, instead of
    trying to patch the existing code. Instead of trying to reuse as many
    existing methods as possible, I opted for defining new methods
    specifically meant for the SnippetsFinder. This requires some extra code
    here and there, but allows us to have much more control over the
    resulting SQL queries. It is these changes that then allow us to produce
    a _much_ more efficient query.
    
    To illustrate how bad the old query was, we will use my own snippets as
    an example. Currently I have 52 snippets, most of which are global ones.
    To retrieve these, you would run the following Ruby code:
    
        use...
    b81102d2d9a4