Self hosted FLOSS fitness/workout, nutrition and weight tracker
Cache the IANA name lookup
Roland Geider8e1213988cee
diff --git a/wger/core/forms.py b/wger/core/forms.pyindex 5dbe61c56..da7117f35 100644--- a/wger/core/forms.py+++ b/wger/core/forms.py@@ -17,7 +17,6 @@# Standard Libraryfrom collections import defaultdictfrom datetime import date-from zoneinfo import available_timezones# Djangofrom django import forms@@ -57,6 +56,7 @@ from django_recaptcha.widgets import ReCaptchaV3# wgerfrom wger.core.models import UserProfile+from wger.core.models.profile import available_timezone_namesclass PasswordInputWithToggle(PasswordInput):@@ -139,7 +139,7 @@ def timezone_choices():limits what the dropdown offers, not what the API stores."""groups = defaultdict(list)- for name in sorted(available_timezones()):+ for name in sorted(available_timezone_names()):if '/' not in name or name.startswith('Etc/'):continueregion, _, city = name.partition('/')diff --git a/wger/core/models/profile.py b/wger/core/models/profile.pyindex 88eb65289..cf14f36bf 100644--- a/wger/core/models/profile.py+++ b/wger/core/models/profile.py@@ -17,6 +17,7 @@# Standard Libraryimport datetimeimport decimal+from functools import lru_cachefrom zoneinfo import (ZoneInfo,ZoneInfoNotFoundError,@@ -70,13 +71,21 @@ def birthdate_validator(birthdate):)+@lru_cache(maxsize=1)+def available_timezone_names() -> frozenset[str]:+ """+ The IANA names, cached: available_timezones() rescans the tzdata on every call+ """+ return frozenset(available_timezones())++def validate_timezone(value: str) -> None:"""Validates that the given string is a real IANA timezone name.An empty value is allowed and means that no client has reported one."""- if value and value not in available_timezones():+ if value and value not in available_timezone_names():raise ValidationError(f'"{value}" is not a valid IANA timezone name')