From 65031511d0110b58a09d5ab2c5fbad94ce835e17 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 16 Jun 2018 00:12:33 +0200 Subject: [PATCH] Use cache to improve ISBN api response time. --- bash/run-prod.sh | 1 + manuels/views.py | 2 ++ manuels_collection/settings.py | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/bash/run-prod.sh b/bash/run-prod.sh index 7d02d9c..3cf9cab 100644 --- a/bash/run-prod.sh +++ b/bash/run-prod.sh @@ -1,4 +1,5 @@ #!/bin/sh yes yes | pipenv run python manage.py migrate && \ +yes yes | pipenv run python manage.py createcachetable && \ pipenv run python manage.py collectstatic --noinput && \ pipenv run gunicorn manuels_collection.wsgi -b 0.0.0.0:8000 --log-file - diff --git a/manuels/views.py b/manuels/views.py index ea47720..e9356ed 100644 --- a/manuels/views.py +++ b/manuels/views.py @@ -7,6 +7,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.http import HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404, redirect from django.urls import reverse +from django.views.decorators.cache import cache_page from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView, DetailView, TemplateView from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm @@ -226,6 +227,7 @@ class ConfirmTeacherView(BaseTeacherView, UpdateView): return response +@cache_page(None) def isbn_api(request, isbn): res = requests.get(f'https://www.decitre.fr/livres/{isbn}.html') diff --git a/manuels_collection/settings.py b/manuels_collection/settings.py index f182b36..1a3fc1f 100644 --- a/manuels_collection/settings.py +++ b/manuels_collection/settings.py @@ -173,3 +173,11 @@ EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' MESSAGE_TAGS = { messages.ERROR: 'danger', } + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', + 'LOCATION': 'manuels_cache', + } +} +