Cache list projects and domains for user

Listing projects and domains for a user based on their role
assignments was noted as being really slow, especially when users
have a lot of assignments. This commit implements caching to mitigate
the issue while we continue to investigate ways to speed up the
assignment API.

Change-Id: I72e398c65f01aa4f9a37f817d184a13ed01089ce
Closes-Bug: 1700852
This commit is contained in:
Lance Bragstad 2017-07-25 17:03:55 +00:00
parent 9fccd38d1b
commit 63124f703a
3 changed files with 20 additions and 0 deletions

View File

@ -223,7 +223,15 @@ class Manager(manager.Manager):
# TODO(henry-nash): We might want to consider list limiting this at some
# point in the future.
@MEMOIZE_COMPUTED_ASSIGNMENTS
def list_projects_for_user(self, user_id):
# FIXME(lbragstad): Without the use of caching, listing effective role
# assignments is slow, especially with large data set (lots of users
# with multiple role assignments). This should serve as a marker in
# case we have the opportunity to come back and optimize this code so
# that it can be performant without having a hard dependency on
# caching. Please see https://bugs.launchpad.net/keystone/+bug/1700852
# for more details.
assignment_list = self.list_role_assignments(
user_id=user_id, effective=True)
# Use set() to process the list to remove any duplicates
@ -233,6 +241,7 @@ class Manager(manager.Manager):
# TODO(henry-nash): We might want to consider list limiting this at some
# point in the future.
@MEMOIZE_COMPUTED_ASSIGNMENTS
def list_domains_for_user(self, user_id):
assignment_list = self.list_role_assignments(
user_id=user_id, effective=True)

View File

@ -332,6 +332,11 @@ class Manager(manager.Manager):
notifications.Audit.disabled(self._PROJECT, project_id,
public=False)
# Drop the computed assignments if the project is being disabled.
# This ensures an accurate list of projects is returned when
# listing projects/domains for a user based on role assignments.
assignment.COMPUTED_ASSIGNMENTS_REGION.invalidate()
if cascade:
self._only_allow_enabled_to_update_cascade(project,
original_project)

View File

@ -0,0 +1,6 @@
---
fixes:
- |
[`bug 1700852 <https://bugs.launchpad.net/keystone/+bug/1700852>`_]
Keystone now supports caching of the `GET|HEAD
/v3/users/{user_id}/projects` API in an effort to improve performance.