Skip to content

Commit

Permalink
#550 Review#1 fixes. Cache in memory db queries
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Aug 28, 2018
1 parent 7244c16 commit 64a8498
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import typing
from functools import partial
from functools import lru_cache, partial

from django import http
from django.db.models import QuerySet
Expand Down Expand Up @@ -159,6 +159,7 @@ def get_context_data(self, **kwargs):
}


@lru_cache(maxsize=64)
def merge_products_context(products):
images = Image.objects.get_main_images_by_pages(
models.ProductPage.objects.filter(shopelectro_product__in=products)
Expand Down Expand Up @@ -212,12 +213,17 @@ class TaggedCategoryPage(CategoryPage):
def get_sorting_index(self):
return int(self.kwargs.get('sorting', 0))

def get_tags(self) -> typing.Union[models.TagQuerySet, None]:
tags = self.kwargs.get('tags')
if not tags:
def get_tags(self) -> typing.Optional[models.TagQuerySet]:

@lru_cache(maxsize=64)
def get_tags(request_tags_: str):
slugs = models.Tag.parse_url_tags(request_tags_)
return models.Tag.objects.filter(slug__in=slugs)

request_tags = self.kwargs.get('tags')
if not request_tags:
return None
slugs = models.Tag.parse_url_tags(tags)
return models.Tag.objects.filter(slug__in=slugs)
return get_tags(request_tags)

def get_products(self):
products = super().get_products()
Expand Down

0 comments on commit 64a8498

Please sign in to comment.