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 #!/bin/sh
yes yes | pipenv run python manage.py migrate && \ 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 python manage.py collectstatic --noinput && \
pipenv run gunicorn manuels_collection.wsgi -b 0.0.0.0:8000 --log-file - 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.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse 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 django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView, DetailView, TemplateView
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
@ -226,6 +227,7 @@ class ConfirmTeacherView(BaseTeacherView, UpdateView):
return response return response
@cache_page(None)
def isbn_api(request, isbn): def isbn_api(request, isbn):
res = requests.get(f'https://www.decitre.fr/livres/{isbn}.html') 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 = { MESSAGE_TAGS = {
messages.ERROR: 'danger', messages.ERROR: 'danger',
} }
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'manuels_cache',
}
}