• 
      

    Fix caching of ID-based Tool queries.

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

    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.

    Summary ID
    Fix caching of ID-based Tool queries.
    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.
    5ac396ce14c9008870ba2b6a44c53fb0878f9dab
    Description From Last Updated

    This blank line should go away.

    daviddavid
    david
    1. 
        
    2. reviewboard/scmtools/managers.py (Diff revision 1)
       
       
      Show all issues

      This blank line should go away.

    3. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-4.0.x (f59ecb6)