From 64a8498e019ebcd178ea945946c4f14bdb650f41 Mon Sep 17 00:00:00 2001 From: duker Date: Tue, 28 Aug 2018 16:51:13 +0300 Subject: [PATCH] #550 Review#1 fixes. Cache in memory db queries --- shopelectro/views/catalog.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py index 480302d7..81445e6f 100644 --- a/shopelectro/views/catalog.py +++ b/shopelectro/views/catalog.py @@ -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 @@ -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) @@ -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()