Fix a search indexing performance regression with ACL diff checks.
Review Request #14165 — Created Sept. 12, 2024 and submitted
When indexing review requests, we determine if a review request is
accessible viareview_request.is_accessible_by()
. Part of this checks
the files in the diffsets for accessibility, using ACL diff checks. This
ends up querying the list of diffsets for each review request and then
each file within it, which drastically slows down diff indexing.We now employ a couple layers of protection against this:
ReviewRequest.get_diffsets()
will now use theprefetch_related()
andselect_related()
caches to determine if it needs to even
perform a new query, or if it can short-cut the result. This saves
the per-diffset and prefetched-files queries.
ReviewRequest._are_diffs_accessible_by()
no longer even calls
get_diffsets()
if there aren't anyFileDiffACLHook
s registered,
which will be the common case.This ensures we don't do any more work than we need to do at any stage
of these checks, and makes a major difference in indexing performance.
All unit tests pass.
Added SQL-level debugging for the database backend and performed a
search index. Withget_diffsets()
being invoked for every diff, I
verified that it used the prefetch cache, avoiding new queries. With
ACL hooks factored in, I verified it never even got to the diffset
query code without faking hooks being available.
Summary | ID |
---|---|
15968ceda0cfdacd5df7f8b56007b9ab1cd5e532 |
Description | From | Last Updated |
---|---|---|
Nit: You could add a comment in the form of # Query description. # # X queries: # # 1. … |
maubin |