-
Notifications
You must be signed in to change notification settings - Fork 29
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
Keyring in database #66
base: main
Are you sure you want to change the base?
Conversation
wagtailcache/models.py
Outdated
def active(self): | ||
return self.filter(expiry__gt=now()) | ||
|
||
def active_for_url_regexes(self, urls=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.
I would prefer to enforce urls: List[str]
in the signature, and make it required, rather than the fallback and casting logic below.
wagtailcache/cache.py
Outdated
# Save the keyring. | ||
_wagcache.set("keyring", keyring) | ||
if urls: | ||
active_keys = KeyringItem.objects.active_for_url_regexes( |
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 this returns a querystring... could you not instead call KeyringItem.objects.active_for_url_regexes(urls).delete()
?
Very nice implementation. Thank you! I left a few comments. Also, another bug fix has been merged in recently (adds a try/catch in |
wagtailcache/models.py
Outdated
self.clear_expired() | ||
return item | ||
|
||
def bulk_delete_cache_keys(self, keys: List[str]) -> 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.
Would prefer if keys is a QuerySet. Because during the delete, we are normally querying keys to delete, flattening them as values list, then passing it in here and re-querying. Double hits to the database. Would prefer to only make one database hit.
655d734
to
dfb02fe
Compare
I've just reverted this to draft because we're finding that calling |
Interesting - are you using ASGI by chance? Or is this caused by concurrent calls to |
It's not ASGI, but there are lots of servers and workers. We were getting many concurrent requests creating calls to I'll tidy it up and re-submit the PR. |
bbf117b
to
25b888e
Compare
- 'testserver' is not a valid netloc so fails Django's validation. - tests for very long URLs
25b888e
to
2386b30
Compare
This moves the keyring into the database to avoid duplication and also keep it up to date.
It would replace #63