Use cache to improve ISBN api response time.

This commit is contained in:
Gabriel Augendre 2018-06-16 00:12:33 +02:00
parent 5d8c2b9c21
commit 65031511d0
3 changed files with 11 additions and 0 deletions

View File

@ -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 -

View File

@ -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')

View File

@ -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',
}
}