Speed up looking up actions by attachment point.
Review Request #14639 — Created Oct. 16, 2025 and updated
When populating the UI, we fetch actions based on various attachment
points. When we do this, the registry has to iterate through every
action every time, returning each one matching the attachment point.
This is algorithmically slow, and only gets worse as we expand usage of
actions.Now, when registering an action, the action gets placed in a cache of
attachment points to actions. Unregistering will remove that action from
the cache. This makes lookup very fast.
Unit tests pass.
Tested various parts of the UI, making sure the right actions are in
the right places.
| Summary | ID |
|---|---|
| 1aadbfc839c86cccf3f52ceb3d31c692005070a4 |
| Description | From | Last Updated |
|---|---|---|
|
We should use a walrus operator here to make a variable out of action.parent_id, like you did below. |
|
|
|
Can use action_id here too. |
|
|
|
Might as well do the walrus operator here too. |
|
|
|
I'm assuming this is part of the future proofing, where in the future action.attachment can possibly be a list of … |
|
|
|
Same notes here about the attachment variable. |
|
|
|
We need to add from __future__ import annotations to this file, especially because you're using dict[...] syntax for type hints. |
|
|
|
Perhaps we should make _by_attachment_point a defaultdict(dict)? |
|
|
|
Just in case an action failed to register properly, we probably should catch KeyError here and log. |
|
|
|
Do we want to make it so we clean up empty dicts from the cache after actions are unregistered? |
|
|
|
These older tests are still using the global actions_registry. Can we update these to construct a _TestActionsRegistry and then get … |
|
-
-
We should use a walrus operator here to make a variable out of
action.parent_id, like you did below. -
-
-
I'm assuming this is part of the future proofing, where in the future
action.attachmentcan possibly be a list of strings?We should name the attachments list
attachmentsinstead of having all variables beattachment. Note that the for loop variable is also namedattachment. After the loop runs, the attachment list variable would now point to the last item in the list instead of the list itself. Doesn't really matter since we don't use the variable again, but its confusing and will cause problems in case we do use it in the future.How about something like this
attachments = action.attachment if attachments: if isinstance(attachments, str): attachments = [attachments] for attachment in attachments: ... -
- Change Summary:
-
- Removed the future-proofing for lists of attachment IDs, since that method won't be used.
- Used some walrus operators in new code.
- Description:
-
When populating the UI, we fetch actions based on various attachment
points. When we do this, the registry has to iterate through every action every time, returning each one matching the attachment point. This is algorithmically slow, and only gets worse as we expand usage of actions. Now, when registering an action, the action gets placed in a cache of
attachment points to actions. Unregistering will remove that action from the cache. This makes lookup very fast. - - There's also a bit of future-proofing thrown in for upcoming support for
- actions that attach to multiple attachment points (part of a larger set - of work for enhanced actions in Review Board 7.1). - Commits:
-
Summary ID 145b2020d753a75f8bc15d98b170e4703441afb9 cf043b93c85f24b3bb432ce50774d56f1540c89a
Checks run (2 succeeded)
-
-
We need to add
from __future__ import annotationsto this file, especially because you're usingdict[...]syntax for type hints. -
-
-
-
These older tests are still using the global
actions_registry. Can we update these to construct a_TestActionsRegistryand then get rid of thetearDown()implementation instead?
- Change Summary:
-
- Moved to a
defaultdictfor the attachment point lookup. - Added logging when an action ID is missing from an attachment point during unregistration.
- Empty attachment points are removed from the lookup table after unregistration.
- Moved to a
- Commits:
-
Summary ID cf043b93c85f24b3bb432ce50774d56f1540c89a 1aadbfc839c86cccf3f52ceb3d31c692005070a4