-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/organization caching #789
base: master
Are you sure you want to change the base?
Conversation
if cache is not None: | ||
self.cache = cache | ||
else: | ||
self.cache = Cache() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if cache is not None: | |
self.cache = cache | |
else: | |
self.cache = Cache() | |
self.cache = cache or Cache() |
@@ -256,14 +256,14 @@ def worker_thread( | |||
|
|||
organizations = Organizations( | |||
role=boto3, | |||
account_id=account_id | |||
account_id=account_id, | |||
cache=cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache=cache | |
cache=cache, |
self.account_id = account_id | ||
self.root_id = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those who wonder, this wasn't used externally, hence we agreed to refactor it.
return organizational_units | ||
|
||
def list_organizational_units_for_parent(self, parent_ou): | ||
print(f'looking for children in {parent_ou}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f'looking for children in {parent_ou}') | |
LOGGER.debug(f'Looking for children in {parent_ou}') |
current.get("Id"), | ||
self.describe_ou_name(current.get("Id")), | ||
) | ||
ou_name = cache.get(current.get("Id")) | ||
ou_name = self.cache.get(current.get("Id")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to cache this at this layer anymore, as you added caching in the describe_ou_name function 👍
Hence, this would suffice:
ou_name = self.cache.get(current.get("Id")) | |
ou_name = self.describe_ou_name(current.get("Id")) |
if not self.cache.exists(current.get("Id")): | ||
self.cache.add( | ||
current.get("Id"), | ||
self.describe_ou_name(current.get("Id")), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required, see next comment.
Why?
With version 4.0, we noticed an increase in the number of Organizations API Calls that are performed during account management and bootstrap, leading to errors or longer execution times.
*Issue #788, #784, #781
What?
Description of changes:
Now Organizations class always use the Cache object, even when it's not passed to the constructor. If passed in the constructor, allow the user of the class to share the same cache with different instances of Organizations. This happens for example in the bootstrap pipeline, where a worker thread for each account is created.
The following methods now make use of Cache:
By submitting this pull request, I confirm that you can use, modify, copy, and
redistribute this contribution, under the terms of your choice.