From c8a083feff5b25581be969694a688c9ac897508b Mon Sep 17 00:00:00 2001 From: Frank Hennige Date: Wed, 19 Jul 2023 23:11:02 +0200 Subject: [PATCH] Cache to avoid multiple database queries --- src/oscar_pg_search/filter_options/filter_forms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/oscar_pg_search/filter_options/filter_forms.py b/src/oscar_pg_search/filter_options/filter_forms.py index 2cdfb69..0ff349a 100644 --- a/src/oscar_pg_search/filter_options/filter_forms.py +++ b/src/oscar_pg_search/filter_options/filter_forms.py @@ -4,6 +4,7 @@ from django.conf import settings from django.urls.base import reverse from django.utils.translation import gettext_lazy as _ +from django.utils.functional import cached_property from oscar.core.loading import get_model from .base_form import FilterFormBase from .product_fields import MultipleChoiceProductField @@ -46,7 +47,7 @@ def initialize(self): del self.fields[fieldname] return result - @property + @cached_property def enabled_attached_fields(self): codes = getattr(settings, 'OSCAR_ATTACHED_PRODUCT_FIELDS', []) return [x for x in codes if x not in self.disabled_fields] @@ -69,7 +70,7 @@ def get_offer_field(self): return {'offer_only': field} return {} - @property + @cached_property def enabled_attributes(self): qs = ProductAttribute.objects.all() if hasattr(ProductAttribute, 'filter_enabled'):