Fix caching of ID-based Tool queries.

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

chipx86
Review Board
release-4.0.x
reviewboard

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

This blank line should go away.

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

    This blank line should go away.

  3. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.0.x (f59ecb6)
Loading...