Skip to content
Snippets Groups Projects
Commit 39b9aca5 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Remove broken caching mechanism

parent 1ba6b773
No related branches found
No related tags found
1 merge request!2Remove broken caching mechanism
from io import BytesIO
import hashlib
import json
import sys
from PIL import Image
from django.conf import settings
from django.core.cache import cache
from django.core.files.storage import default_storage as storage
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.db import models
......@@ -29,7 +26,6 @@ config = getattr(settings, 'FAVICON_CONFIG', config)
if "shortcut icon" not in config or 32 not in config["shortcut icon"]:
config.setdefault("shortcut_icon", []).append(32)
config_cache_key = "favicons_" + hashlib.sha1(json.dumps(config, sort_keys=True).encode()).hexdigest()
image_path = getattr(settings, "FAVICON_PATH", "favicon")
......@@ -120,13 +116,10 @@ class Favicon(models.Model):
if self.isFavicon:
Favicon.on_site.exclude(pk=self.pk).update(isFavicon=False)
super(Favicon, self).save(*args, **kwargs)
cache.delete(config_cache_key)
super().save(*args, **kwargs)
if self.faviconImage:
html = self.as_html(update=True)
cache.set(config_cache_key, html, timeout=None)
self.get_favicons(update=True)
class FaviconImg(models.Model):
......
......@@ -2,7 +2,7 @@ from django import template
from django.core.cache import cache
from django.utils.safestring import mark_safe
from favicon.models import Favicon, config_cache_key
from favicon.models import Favicon
register = template.Library()
......@@ -18,14 +18,9 @@ def place_favicon(context):
"""
html = cache.get(config_cache_key)
if html:
return mark_safe(html)
fav = Favicon.on_site.filter(isFavicon=True).first()
if not fav:
return mark_safe('<!-- no favicon -->')
html = fav.as_html()
cache.set(config_cache_key, html, timeout=None)
return mark_safe(html)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment