mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-04-24 08:54:42 +00:00
Save a few more database queries
This commit is contained in:
parent
3477319298
commit
f57ca2f769
2 changed files with 8 additions and 9 deletions
|
|
@ -55,9 +55,9 @@ class Loader(BaseLoader):
|
|||
# in the cache indicating that queries failed, with the current
|
||||
# timestamp.
|
||||
site = Site.objects.get_current()
|
||||
cache_key = get_cache_key(template_name)
|
||||
cache_key = get_cache_key(template_name, current_site=site)
|
||||
# Not found in cache, move on.
|
||||
cache_notfound_key = get_cache_notfound_key(template_name)
|
||||
cache_notfound_key = get_cache_notfound_key(template_name, current_site=site)
|
||||
if cache:
|
||||
try:
|
||||
backend_template = cache.get(cache_key)
|
||||
|
|
|
|||
|
|
@ -22,14 +22,13 @@ def get_cache_backend():
|
|||
cache = get_cache_backend()
|
||||
|
||||
|
||||
def get_cache_key(name, site=None):
|
||||
if site is None:
|
||||
site = Site.objects.get_current()
|
||||
return f"dbtemplates::{slugify(name)}::{site.pk}"
|
||||
def get_cache_key(name, current_site=None):
|
||||
current_site = current_site or Site.objects.get_current()
|
||||
return f"dbtemplates::{slugify(name)}::{current_site.pk}"
|
||||
|
||||
|
||||
def get_cache_notfound_key(name):
|
||||
return get_cache_key(name) + "::notfound"
|
||||
def get_cache_notfound_key(name, current_site=None):
|
||||
return get_cache_key(name, current_site=current_site) + "::notfound"
|
||||
|
||||
|
||||
def remove_notfound_key(instance):
|
||||
|
|
@ -60,4 +59,4 @@ def remove_cached_template(instance, **kwargs):
|
|||
in the database was changed or deleted.
|
||||
"""
|
||||
for site in instance.sites.all():
|
||||
cache.delete(get_cache_key(instance.name, site=site))
|
||||
cache.delete(get_cache_key(instance.name, current_site=site))
|
||||
|
|
|
|||
Loading…
Reference in a new issue