Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Cache ingredient responses

Roland Geidere792ada8f802
diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.py
index f8b2d13b5..86d412b96 100644
--- a/wger/nutrition/api/views.py
+++ b/wger/nutrition/api/views.py
@@ -19,7 +19,10 @@
import datetime
# Django
+from django.conf import settings
from django.shortcuts import get_object_or_404
+from django.utils.decorators import method_decorator
+from django.views.decorators.cache import cache_page
# Third Party
from easy_thumbnails.alias import aliases
@@ -89,6 +92,10 @@ class IngredientViewSet(viewsets.ReadOnlyModelViewSet):
'license_author',
)
+ @method_decorator(cache_page(settings.WGER_SETTINGS['EXERCISE_CACHE_TTL']))
+ def dispatch(self, request, *args, **kwargs):
+ super().dispatch(request, *args, **kwargs)
+
@action(detail=True)
def get_values(self, request, pk):
"""
@@ -203,6 +210,10 @@ class ImageViewSet(viewsets.ReadOnlyModelViewSet):
ordering_fields = '__all__'
filterset_fields = ('uuid', 'source_url', 'ingredient_id')
+ @method_decorator(cache_page(settings.WGER_SETTINGS['EXERCISE_CACHE_TTL']))
+ def dispatch(self, request, *args, **kwargs):
+ super().dispatch(request, *args, **kwargs)
+
class WeightUnitViewSet(viewsets.ReadOnlyModelViewSet):
"""
diff --git a/wger/nutrition/management/commands/download-off-ingredient-images.py b/wger/nutrition/management/commands/download-off-ingredient-images.py
index 4e30a4b82..d519d1a45 100644
--- a/wger/nutrition/management/commands/download-off-ingredient-images.py
+++ b/wger/nutrition/management/commands/download-off-ingredient-images.py
@@ -20,8 +20,8 @@ from django.conf import settings
from django.core.management.base import BaseCommand
# wger
-from wger.nutrition.tasks import fetch_ingredient_image
from wger.nutrition.models import MealItem
+from wger.nutrition.tasks import fetch_ingredient_image
logger = logging.getLogger(__name__)