Performances

- Introduction du cache
- Outil de debug
- url locale
- mise à jour packages
This commit is contained in:
Jean-Marie Favreau 2024-08-29 21:02:50 +02:00
parent 4da9b68a7c
commit bc19358ed3
9 changed files with 67 additions and 34 deletions

View File

@ -108,6 +108,10 @@ class CalendarList:
# end the last day of the last week
self.c_lastdate = lastdate + timedelta(days=6 - lastdate.weekday())
self.calendar_days = None
def build_internal(self):
# create a list of DayInCalendars
self.create_calendar_days()
@ -118,6 +122,12 @@ class CalendarList:
for i, c in self.calendar_days.items():
c.filter_events()
def get_calendar_days(self):
if self.calendar_days is None:
self.build_internal()
return self.calendar_days
def today_in_calendar(self):
return self.firstdate <= self.now and self.lastdate >= self.now
@ -173,11 +183,11 @@ class CalendarList:
return hasattr(self, "month")
def calendar_days_list(self):
return list(self.calendar_days.values())
return list(self.get_calendar_days().values())
def export_to_ics(self):
from .models import Event
events = [event for day in self.calendar_days.values() for event in day.events]
events = [event for day in self.get_calendar_days().values() for event in day.events]
return Event.export_to_ics(events)

View File

@ -52,6 +52,7 @@ INSTALLED_APPS = [
"location_field.apps.DefaultConfig",
"django.contrib.postgres",
"robots",
"debug_toolbar",
]
SITE_ID = 1
@ -67,6 +68,7 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
# "django.middleware.cache.UpdateCacheMiddleware",
# "django.middleware.common.CommonMiddleware",
# "django.middleware.cache.FetchFromCacheMiddleware",
@ -197,14 +199,14 @@ COMPRESS_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)
# cache
#CACHES = {
# "default": {
# "BACKEND": "django.core.cache.backends.redis.RedisCache",
# "LOCATION": REDIS_URL,
# "KEY_PREFIX": "agenda",
# "TIMEOUT": 60 * 15,
# }
#}
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": REDIS_URL,
"KEY_PREFIX": "agenda",
"TIMEOUT": 60 * 15,
}
}
# EMAIL settings
@ -239,3 +241,8 @@ LOCATION_FIELD = {
ROBOTS_USE_SITEMAP = False
# debug
if DEBUG:
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "10.0.2.2"]

View File

@ -8,6 +8,7 @@
{% load event_extra %}
{% load utils_extra %}
{% load static %}
{% load cache %}
{% block entete_header %}
@ -22,6 +23,8 @@
{% block content %}
{% cache 500 day user.is_authenticated calendar.firstdate filter.to_str %}
{% include "agenda_culturel/filter-inc.html" with filter=filter %}
@ -100,5 +103,6 @@
</div>
{% endcache %}
{% endblock %}
{% endblock %}

View File

@ -8,7 +8,7 @@
{% load event_extra %}
{% load utils_extra %}
{% load static %}
{% load cache %}
{% block entete_header %}
{% css_categories %}
@ -22,6 +22,7 @@
{% block content %}
{% cache 500 month user.is_authenticated calendar.firstdate filter.to_str %}
{% include "agenda_culturel/filter-inc.html" with filter=filter %}
@ -65,7 +66,7 @@
{% endif %}
</footer>
</article>
{% endcache %}
{% endblock %}

View File

@ -2,7 +2,7 @@
{% load i18n %}
{% load cache %}
{% load cat_extra %}
{% load event_extra %}
{% load utils_extra %}
@ -19,6 +19,7 @@
{% block content %}
{% cache 500 week user.is_authenticated calendar.firstdate filter.to_str %}
{% include "agenda_culturel/filter-inc.html" with filter=filter %}
@ -61,6 +62,6 @@
<a role="button" data-tooltip="Copiez ce lien et importez-le dans votre agenda" href="{% url 'export_ical' %}?{{ filter.get_url }}">Export ical {% picto_from_name "calendar" %}</a>
</footer>
</article>
{% endblock %}
{% endcache %}
{% endblock %}

View File

@ -28,6 +28,7 @@
{% endblock %}
</head>
{% load event_extra %}
{% load cache %}
{% load contactmessages_extra %}
{% load utils_extra %}
{% load duplicated_extra %}

View File

@ -172,7 +172,7 @@ urlpatterns = [
export_ical,
name="export_ical"),
re_path(r'^robots\.txt', include('robots.urls')),
path("__debug__/", include("debug_toolbar.urls")),
]
if settings.DEBUG:

View File

@ -235,20 +235,29 @@ class EventFilter(django_filters.FilterSet):
def get_url_without_filters(self):
return self.request.get_full_path().split("?")[0]
def get_cleaned_data(self, name):
try:
return self.form.cleaned_data[name]
except AttributeError:
return {}
except KeyError:
return {}
def get_categories(self):
return self.form.cleaned_data["category"]
return self.get_cleaned_data("category")
def get_tags(self):
return self.form.cleaned_data["tags"]
return self.get_cleaned_data("cleaned_data")
def get_exclude_tags(self):
return self.form.cleaned_data["exclude_tags"]
return self.get_cleaned_data("exclude_tags")
def get_status(self):
return self.form.cleaned_data["status"]
return self.get_cleaned_data("status")
def get_cities(self):
return self.form.cleaned_data["city"]
return self.get_cleaned_data("city")
def to_str(self, prefix=''):
result = ' '.join([c.name for c in self.get_categories()] + [t for t in self.get_tags()] + [c for c in self.get_cities()])
@ -259,7 +268,7 @@ class EventFilter(django_filters.FilterSet):
def get_status_names(self):
if "status" in self.form.cleaned_data:
return [
dict(Event.STATUS.choices)[s] for s in self.form.cleaned_data["status"]
dict(Event.STATUS.choices)[s] for s in self.get_cleaned_data("status")
]
else:
return []
@ -277,19 +286,18 @@ class EventFilter(django_filters.FilterSet):
def is_active(self, only_categories=False):
if only_categories:
return len(self.form.cleaned_data["category"]) != 0
return len(self.get_cleaned_data("category")) != 0
else:
if (
"status" in self.form.cleaned_data
and len(self.form.cleaned_data["status"]) != 0
len(self.get_cleaned_data("status")) != 0
):
return True
return (
len(self.form.cleaned_data["category"]) != 0
or len(self.form.cleaned_data["tags"]) != 0
or len(self.form.cleaned_data["exclude_tags"]) != 0
or len(self.form.cleaned_data["recurrences"]) != 0
or len(self.form.cleaned_data["city"]) != 0
len(self.get_cleaned_data("category")) != 0
or len(self.get_cleaned_data("tags")) != 0
or len(self.get_cleaned_data("exclude_tags")) != 0
or len(self.get_cleaned_data("recurrences")) != 0
or len(self.get_cleaned_data("city")) != 0
)
def is_selected(self, cat):

View File

@ -6,8 +6,8 @@ click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
Django==4.2.7
django-cors-headers==4.3.1
Django==4.2.9
django-cors-headers==4.4.0
gunicorn==21.2.0
kombu==5.3.3
prompt-toolkit==3.0.41
@ -39,3 +39,4 @@ bbcode==1.1.0
json5==0.9.25
django-location-field==2.7.3
django-robots==6.1
django-debug-toolbar==4.4.6