Skip to content

Commit

Permalink
Merge pull request #884 from Pikkupomo/cache-product-list
Browse files Browse the repository at this point in the history
Cache product list
  • Loading branch information
gurch101 committed Oct 28, 2016
2 parents 591980a + babd251 commit 930818c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions shuup/front/forms/product_list_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import get_language

from shuup.core import cache
from shuup.core.models import (
Category, Manufacturer, ProductVariationVariable, ShopProduct
)
Expand Down Expand Up @@ -230,6 +231,7 @@ def get_fields(self, request, category=None):
else:
# Show only first level when there is no category selected
queryset = base_queryset.filter(parent=None)

return [
(
"categories",
Expand Down Expand Up @@ -269,6 +271,11 @@ def get_fields(self, request, category=None):
if not category:
return

cache_key = "productvariationfilter:%s" % category.pk
cached_fields = cache.get(cache_key)
if cached_fields:
return cached_fields

variation_values = defaultdict(set)
for variation in ProductVariationVariable.objects.filter(product__shop_products__categories=category):
for value in variation.values.all():
Expand All @@ -283,6 +290,7 @@ def get_fields(self, request, category=None):
forms.MultipleChoiceField(
choices=choices, required=False, label=capfirst(variation_key), widget=FilterWidget())
))
cache.set(cache_key, fields, 60 * 15)
return fields

def get_queryset(self, queryset, data):
Expand Down
2 changes: 1 addition & 1 deletion shuup/front/templates/shuup/front/macros/product.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Inheritance order for product macors:
{% if show_image %}
{% set primary_image_thumb = product.primary_image|thumbnail(size=thumbnail_size) %}
<div class="image-wrap">
{% if product.primary_image %}
{% if product.primary_image and primary_image_thumb %}
{% set image_url = primary_image_thumb %}
{% else %}
{% set image_url = STATIC_URL ~ "shuup/front/img/no_image.png" %}
Expand Down

0 comments on commit 930818c

Please sign in to comment.