• 
      

    Fix caching of ID-based Tool queries.

    Review Request #11132 — Created Aug. 10, 2020 and submitted — Latest diff uploaded

    Information

    Review Board
    release-4.0.x

    Reviewers

    When performing a Tool.objects.get(...) or a self.tool query, we
    attempt to populate a cache of known Tool objects and then look up in
    that cache. Those entries very rarely change, and are frequently
    queried, so we want to limit the database hits.

    There was a regression in this caching. While debugging performance
    regressions from the Django 1.11 port, I noticed that we were getting
    repeated queries for the same tools. This happened because Q() objects
    were being used in places (apparently from accessing repository.tool).
    It's not clear yet whether this was an issue in Review Board 3.0 (and if
    so, this will be backported).

    This change fixes this up by making the caching logic a lot more
    extensive. We now check for all sorts of variations of an ID lookup,
    factoring in id/pk fields, pk=... and pk__exact=... keyword
    arguments, and Q() queries.

    Unit tests were added to catch caching regressions.

    Unit tests pass.

    Manually verified that this fixed multiple queries for the same Tool
    in the profiling logs.

    Commits

    Files