def bump_price_expiration(shop_ids: Iterable[int]): """ Bump price expiration cache for shop ids """ for shop_id in shop_ids: context_cache.bump_cache_for_item( _get_price_expiration_cache_key(shop_id))
def handle_cross_sell_post_save(sender, instance, **kwargs): shop_ids = list( ShopProduct.objects.filter( product__in=[instance.product1, instance.product2] ).values_list("shop", flat=True).distinct() ) for shop_id in shop_ids: context_cache.bump_cache_for_item(cache_utils.get_cross_sells_cache_item(shop_id))
def handle_cross_sell_post_save(sender, instance, **kwargs): shop_ids = list( ShopProduct.objects.filter( product__in=[instance.product1, instance.product2]).values_list( "shop", flat=True).distinct()) for shop_id in shop_ids: context_cache.bump_cache_for_item( cache_utils.get_cross_sells_cache_item(shop_id))
def bump_price_info_cache(shop): """ Bump the price info cache for the entire shop :param int|Shop shop: the shop to be bump caches """ from shuup.core.models import Shop shop_id = shop.pk if isinstance(shop, Shop) else int(shop) context_cache.bump_cache_for_item(_get_price_info_namespace_for_shop(shop_id))
def bump_price_info_cache(shop): """ Bump the price info cache for the entire shop :param int|Shop shop: the shop to be bump caches """ from shuup.core.models import Shop shop_id = shop.pk if isinstance(shop, Shop) else int(shop) context_cache.bump_cache_for_item(_get_price_info_namespace_for_shop(shop_id))
def bump_price_expiration(shops): """ Bump price expiration cache for shops :param itetable[int|Shop] shops: list of shops to bump caches """ from shuup.core.models import Shop shop_ids = [shop.pk if isinstance(shop, Shop) else int(shop) for shop in shops] for shop_id in shop_ids: context_cache.bump_cache_for_item(_get_price_expiration_cache_key(shop_id))
def handle_manufacturer_post_save(sender, instance, **kwargs): """ Everytime a manufacturer gets saved, we bump our caches for manufacturer's shop or all shops """ if instance.shops.exists(): for shop in instance.shops.only("pk").all(): context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop)) else: # worst scenario ever for shop in Shop.objects.only("pk").all(): context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
def handle_manufacturer_post_save(sender, instance, **kwargs): """ Everytime a manufacturer gets saved, we bump our caches for manufacturer's shop or all shops """ if instance.shops.exists(): for shop in instance.shops.only("pk").all(): context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop)) else: # worst scenario ever for shop in Shop.objects.only("pk").all(): context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
def bump_price_expiration(shops): """ Bump price expiration cache for shops :param itetable[int|Shop] shops: list of shops to bump caches """ from shuup.core.models import Shop shop_ids = [shop.pk if isinstance(shop, Shop) else int(shop) for shop in shops] for shop_id in shop_ids: context_cache.bump_cache_for_item(_get_price_expiration_cache_key(shop_id))
def bump_cache_for_shop_id(shop_id): context_cache.bump_cache_for_item( cache_utils.get_listed_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_best_selling_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_newest_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_products_for_category_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_random_products_cache_item(shop_id))
def handle(self, *args, **options): # Clear all existing ProductCrossSell objects ProductCrossSell.objects.filter(type=ProductCrossSellType.BOUGHT_WITH).delete() # Handle all ordered products ordered_product_ids = OrderLine.objects.filter( type=OrderLineType.PRODUCT).values_list("product_id", flat=True).distinct() for product_id in ordered_product_ids.distinct(): add_bought_with_relations_for_product(product_id) for shop in Shop.objects.all(): context_cache.bump_cache_for_item(cache_utils.get_cross_sells_cache_item(shop))
def set_configuration(shop=None, category=None, data=None): if category and category.pk: configuration.set(None, _get_category_configuration_key(category), data) elif shop: configuration.set(shop, FACETED_DEFAULT_CONF_KEY, data) cache.bump_version(get_theme_cache_key(shop)) # clear active keys context_cache.bump_cache_for_item(category) if not category: from shuup.core.models import Category for cat_pk in Category.objects.all().values_list("pk", flat=True): context_cache.bump_cache_for_pk(Category, cat_pk)
def set_configuration(shop=None, category=None, data=None): if category and category.pk: configuration.set(None, _get_category_configuration_key(category), data) elif shop: configuration.set(shop, FACETED_DEFAULT_CONF_KEY, data) cache.bump_version(get_theme_cache_key(shop)) # clear active keys context_cache.bump_cache_for_item(category) if not category: from shuup.core.models import Category for cat_pk in Category.objects.all().values_list("pk", flat=True): context_cache.bump_cache_for_pk(Category, cat_pk)
def handle_context_cache_item_bumped(sender, item, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if isinstance(item, ShopProduct): shop = item.shop context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop)) bump_product_queryset_cache() elif isinstance(item, Product): bump_product_queryset_cache()
def handle_context_cache_item_bumped(sender, item, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if isinstance(item, ShopProduct): shop = item.shop context_cache.bump_cache_for_item( cache_utils.get_listed_products_cache_item(shop)) context_cache.bump_cache_for_item( cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item( cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item( cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item( cache_utils.get_random_products_cache_item(shop))
def handle_context_cache_item_bumped(sender, item, shop=None, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if issubclass(sender, ShopProduct): if not shop and isinstance(item, int): shop = ShopProduct.objects.get(id=item).shop elif not shop: shop = item.shop context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop)) bump_product_queryset_cache() elif issubclass(sender, Product): bump_product_queryset_cache()
def bump_product_queryset_cache(): context_cache.bump_cache_for_item("product_queryset")
def bump_product_queryset_cache(): context_cache.bump_cache_for_item("product_queryset")
def handle_context_cache_item_bumped(sender, **kwargs): shop_id = kwargs.get("shop_id", None) if shop_id: cache_key = PRODUCT_HIGHLIGHT_CACHE_KEY_PREFIX % {"shop_id": shop_id} context_cache.bump_cache_for_item(cache_key)