Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
index ee7dd6fee..ecefa08a7 100644
--- a/wger/nutrition/models/ingredient.py
+++ b/wger/nutrition/models/ingredient.py
@@ -23,7 +23,6 @@ from json import JSONDecodeError
# Django
from django.conf import settings
from django.contrib.postgres.indexes import GinIndex
-from django.core.cache import cache
from django.core.validators import (
MaxValueValidator,
MinLengthValidator,
@@ -51,7 +50,6 @@ from wger.nutrition.dataclasses import IngredientData
from wger.nutrition.managers import ApproximateCountManager
from wger.nutrition.models.ingredient_category import IngredientCategory
from wger.nutrition.models.sources import Source
-from wger.utils.cache import cache_mapper
from wger.utils.constants import TWOPLACES
from wger.utils.language import load_language
from 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 representation
diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py
index 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 settings
from django.contrib.auth.mixins import (
LoginRequiredMixin,
PermissionRequiredMixin,
)
-from django.core.cache import cache
from django.http import HttpResponseForbidden
from 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_mapper
from wger.utils.constants import PAGINATION_OBJECTS_PER_PAGE
from 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'] = ingredient
context['image'] = ingredient.get_image(request)
diff --git a/wger/utils/cache.py b/wger/utils/cache.py
index 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