From 63124f703a81074793360c1b91711b6ee5a76196 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Tue, 25 Jul 2017 17:03:55 +0000 Subject: [PATCH] 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 --- keystone/assignment/core.py | 9 +++++++++ keystone/resource/core.py | 5 +++++ releasenotes/notes/bug-1700852-de775d0eb2ddfdd1.yaml | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 releasenotes/notes/bug-1700852-de775d0eb2ddfdd1.yaml diff --git a/keystone/assignment/core.py b/keystone/assignment/core.py index 6db4d32093..c9a84e9b5f 100644 --- a/keystone/assignment/core.py +++ b/keystone/assignment/core.py @@ -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) diff --git a/keystone/resource/core.py b/keystone/resource/core.py index 322d4ab4a9..1f7423eae3 100644 --- a/keystone/resource/core.py +++ b/keystone/resource/core.py @@ -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) diff --git a/releasenotes/notes/bug-1700852-de775d0eb2ddfdd1.yaml b/releasenotes/notes/bug-1700852-de775d0eb2ddfdd1.yaml new file mode 100644 index 0000000000..903b1e9343 --- /dev/null +++ b/releasenotes/notes/bug-1700852-de775d0eb2ddfdd1.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + [`bug 1700852 `_] + Keystone now supports caching of the `GET|HEAD + /v3/users/{user_id}/projects` API in an effort to improve performance.