Repository navigation
Conversation
list_roles() asked keystone for the role assignments of a project and
then fetched the name of every group and every role by id, one request
each. That is two requests per project member, on top of the listing:
six members cost thirteen requests, and fifty would cost a hundred.
The role lookup was the plainer waste of the two, since a cloud has a
handful of distinct roles and it fetched the same ones once per
assignment.
include_names makes keystone fill the names in, so this is now one
request whatever the size of the project. The same file already asks
that way in __get_role_assignments(), so nothing new is required of
keystone. Measured on a six member project: thirteen requests and
161ms become one and 15ms.
What callers get back is unchanged - a list of {'group': name, 'role':
name} - and all of them use only those two keys.
It also no longer raises on a role assignment it cannot report. The old
loop rebound 'role' from the assignment to the role object and then
read 'role.group' in the branch for a group it had not found, so both
an assignment held by a user rather than a group, and a group missing
from keystone, ended in AttributeError instead of the debug line that
was meant to be printed. Such an assignment is now skipped and logged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keystone.list_roles()asked keystone for a project's role assignments and thenfetched the name of every group and every role by id, one request each. That is
two requests per project member on top of the listing: six members cost thirteen
requests, fifty would cost a hundred. The role lookup was the plainer waste,
since a cloud has a handful of distinct roles and the same ones were fetched once
per assignment.
include_names=Truemakes keystone fill the names in, so this is one requestwhatever the size of the project.
__get_role_assignments()in the same filealready asks that way, so nothing new is required of keystone, and
python-keystoneclienthas carried the parameter since 3.7.0.Measured on a six member project: thirteen requests and 161ms become one and
15ms. Small in absolute terms, but it was 2 requests per member and is now
flat.
Also fixes a latent AttributeError
The old loop rebound
rolefrom the assignment to the role object and then readrole.groupin the branch for a group it had not found:So both an assignment held by a user rather than a group, and a group missing
from keystone, ended in
AttributeError: 'Assignment' object has no attribute 'group'instead of the debug line that was meant to be printed. Such anassignment is now skipped and logged.
Compatibility
The return value is unchanged, a list of
{'group': name, 'role': name}. Allseven callers use only those two keys or
len():user.py,project.py,report.py,object.py(twice),report2.pyandhimlarcli/printer.py.Testing
Checked against a fake keystone covering the assignment shapes that matter -
a group holding a role, a disabled group, a second role, an assignment on a user,
and one where keystone did not fill the names in - asserting the resulting rows,
that exactly one request is made, and that the per-id
roles.get/groups.getpaths are never reached. The old loop was run against the user assignment
separately to confirm it did raise.
pylint -Ereports the same three pre-existing findings as master, none in thisfunction.
Not yet exercised against a live cloud. Worth running a command that calls it
(
project.py,object.pyoruser.py) against a project whose membership isknown before merging.
🤖 Generated with Claude Code