Skip to content

Commit

Permalink
Cache to avoid multiple database queries
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHennige committed Jul 19, 2023
1 parent 36a1c75 commit c8a083f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/oscar_pg_search/filter_options/filter_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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'):
Expand Down

0 comments on commit c8a083f

Please sign in to comment.