Browse Source

Use cache to improve ISBN api response time.

master
Gabriel Augendre 3 years ago
parent
commit
65031511d0
  1. 1
      bash/run-prod.sh
  2. 2
      manuels/views.py
  3. 8
      manuels_collection/settings.py

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

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

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

Loading…
Cancel
Save