Fix caching of ID-based Tool queries.
Review Request #11132 — Created Aug. 10, 2020 and submitted — Latest diff uploaded
When performing a
Tool.objects.get(...)
or aself.tool
query, we
attempt to populate a cache of knownTool
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 becauseQ()
objects
were being used in places (apparently from accessingrepository.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 inid
/pk
fields,pk=...
andpk__exact=...
keyword
arguments, andQ()
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.