-
Notifications
You must be signed in to change notification settings - Fork 60
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
Cache public tenant #1368
base: master
Are you sure you want to change the base?
Cache public tenant #1368
Conversation
This adds a method on the `Tenant` model manager, `get_public_tenant()` which can be called with `Tenant.objects.get_public_tenant()`. The public tenant record will be added to/retrieved from the cache. A new cache inheriting from `TenantCache` was added to allow for a custom TTL and key to be used for the public tenant (open to feedback here, I just didn't want to refactor too much initially).
This adds a configurable `PUBLIC_TENANT_CACHE_LIFETIME` defaulted to 24hrs to be used on the new cache object, allowing for some inheritance from `TenantCache` while also having a custom TTL and key for retrieving and setting based on the name, since the public tenant has no org.
Update instances of `Tenant.objects.get(tenant_name="public")` to use the new method on the `Tenant` model manager.
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.
LGTM, not sure if the TTL is useful though, I can't think of a situation that we need to expire it
@astrozzc yeah, that's fair and what I was thinking as well. Wasn't sure if there would be any situation where things might get into a weird state, etc., and wanted to get feedback on that (hence the question in the PR around TTL for this). |
This PR looks good and we basically use only id of public tenant in queries - so it also doesn't look like that TTL is needed.
Example of using static variable(code was not run):
@coderbydesign @astrozzc What do you think about it ? Do you know about anything what would not work with this approach ? |
Link(s) to Jira
Description of Intent of Change(s)
QUESTIONS
TenantCache
to make it more generic, or keep it separate?There are several places in the code we query the public tenant. We should DRY this process and also optimize the lookups by caching the tenant.
Add method to retrieve the public tenant
This adds a method on the
Tenant
model manager,get_public_tenant()
which canbe called with
Tenant.objects.get_public_tenant()
.The public tenant record will be added to/retrieved from the cache. A new cache
inheriting from
TenantCache
was added to allow for a custom TTL and key to beused for the public tenant (open to feedback here, I just didn't want to refactor
too much initially).
Add the PublicTenantCache and TTL config
This adds a configurable
PUBLIC_TENANT_CACHE_LIFETIME
defaulted to 24hrs tobe used on the new cache object, allowing for some inheritance from
TenantCache
while also having a custom TTL and key for retrieving and setting based on the
name, since the public tenant has no org.
Use the model manager to query for the public tenant
Update instances of
Tenant.objects.get(tenant_name="public")
to use the newmethod on the
Tenant
model manager.Local Testing
Start the service, and after hitting an endpoint, check redis:
Note that this k/v should exist, and you should see a TTL of ~24 hours.
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist