Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove the cache for individual ingredients
Roland Geider67c2323e57c2
diff --git a/wger/nutrition/models/ingredient.py b/wger/nutrition/models/ingredient.pyindex ee7dd6fee..ecefa08a7 100644--- a/wger/nutrition/models/ingredient.py+++ b/wger/nutrition/models/ingredient.py@@ -23,7 +23,6 @@ from json import JSONDecodeError# Djangofrom django.conf import settingsfrom django.contrib.postgres.indexes import GinIndex-from django.core.cache import cachefrom django.core.validators import (MaxValueValidator,MinLengthValidator,@@ -51,7 +50,6 @@ from wger.nutrition.dataclasses import IngredientDatafrom wger.nutrition.managers import ApproximateCountManagerfrom wger.nutrition.models.ingredient_category import IngredientCategoryfrom wger.nutrition.models.sources import Source-from wger.utils.cache import cache_mapperfrom wger.utils.constants import TWOPLACESfrom wger.utils.language import load_languagefrom wger.utils.models import AbstractLicenseModel@@ -342,14 +340,6 @@ class Ingredient(AbstractLicenseModel, models.Model):else:return reverse('nutrition:ingredient:view', kwargs={'pk': self.id, 'slug': slug})- def save(self, *args, **kwargs):- """- Reset the cache- """-- super(Ingredient, self).save(*args, **kwargs)- cache.delete(cache_mapper.get_ingredient_key(self.id))-def __str__(self):"""Return a more human-readable representationdiff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.pyindex 4cc42253e..01708d29c 100644--- a/wger/nutrition/views/ingredient.py+++ b/wger/nutrition/views/ingredient.py@@ -18,12 +18,10 @@import logging# Django-from django.conf import settingsfrom django.contrib.auth.mixins import (LoginRequiredMixin,PermissionRequiredMixin,)-from django.core.cache import cachefrom django.http import HttpResponseForbiddenfrom django.shortcuts import (get_object_or_404,@@ -48,7 +46,6 @@ from wger.nutrition.forms import (UnitChooserForm,)from wger.nutrition.models import Ingredient-from wger.utils.cache import cache_mapperfrom wger.utils.constants import PAGINATION_OBJECTS_PER_PAGEfrom wger.utils.generic_views import (WgerDeleteMixin,@@ -188,14 +185,7 @@ class IngredientListView(ListView):def view(request, pk, slug=None):context = {}- ingredient = cache.get(cache_mapper.get_ingredient_key(int(pk)))- if not ingredient:- ingredient = get_object_or_404(Ingredient, pk=pk)- cache.set(- cache_mapper.get_ingredient_key(ingredient),- ingredient,- settings.WGER_SETTINGS['INGREDIENT_CACHE_TTL'],- )+ ingredient = get_object_or_404(Ingredient, pk=pk)context['ingredient'] = ingredientcontext['image'] = ingredient.get_image(request)diff --git a/wger/utils/cache.py b/wger/utils/cache.pyindex 9d185a337..ad79377b6 100644--- a/wger/utils/cache.py+++ b/wger/utils/cache.py@@ -56,12 +56,6 @@ class CacheKeyMapper:"""return f'language-{self.get_pk(param)}'- def get_ingredient_key(self, param):- """- Return the ingredient cache key- """- return f'ingredient-{self.get_pk(param)}'-def get_workout_log_list(self, hash_value):"""Return the workout canonical representation