From f5187d1938b87391ae160116e4d00745787f3155 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 25 May 2023 15:46:07 +0100 Subject: [PATCH] Don't redundantly try and find a site We don't actually use the site. In all cases, it's sensible to fall back to passing the request instead, as this should improve cache ratios --- CHANGELOG.txt | 1 + docs/releases/5.1.md | 1 + wagtail/contrib/settings/context_processors.py | 12 +----------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 78ee05d3ad..0f001c1f76 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -42,6 +42,7 @@ Changelog * Maintenance: Split out a base listing view from generic index view (Matt Westcott) * Maintenance: Update type hints in admin/ui/components.py so that `parent_context` is mutable (Andreas Nüßlein) * Maintenance: Deprecate `UserPagePermissionsProxy` (Sage Abdullah) + * Maintenance: Optimise the Settings context processor to avoid redundantly finding a Site to improve cache ratios (Jake Howard) 5.0.2 (21.06.2023) diff --git a/docs/releases/5.1.md b/docs/releases/5.1.md index c334eaad2e..a471821509 100644 --- a/docs/releases/5.1.md +++ b/docs/releases/5.1.md @@ -63,6 +63,7 @@ FieldPanels can now be marked as read-only with the `read_only=True` keyword arg * Split out a base listing view from generic index view (Matt Westcott) * Update type hints in admin/ui/components.py so that `parent_context` is mutable (Andreas Nüßlein) * Deprecate `UserPagePermissionsProxy` (Sage Abdullah) + * Optimise the Settings context processor to avoid redundantly finding a Site to improve cache ratios (Jake Howard) ## Upgrade considerations diff --git a/wagtail/contrib/settings/context_processors.py b/wagtail/contrib/settings/context_processors.py index 8562a7e8f6..487439b85d 100644 --- a/wagtail/contrib/settings/context_processors.py +++ b/wagtail/contrib/settings/context_processors.py @@ -1,5 +1,3 @@ -from django.utils.functional import SimpleLazyObject - from wagtail.contrib.settings.models import BaseGenericSetting, BaseSiteSetting from wagtail.models import Site @@ -74,12 +72,4 @@ class SettingModuleProxy(dict): def settings(request): - # Delay query until settings values are needed - def _inner(request): - site = Site.find_for_request(request) - if site is None: - return SettingProxy(request_or_site=None) - - return SettingProxy(request_or_site=request) - - return {"settings": SimpleLazyObject(lambda: _inner(request))} + return {"settings": SettingProxy(request_or_site=request)}