Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Drop usages of prefetched_for_webhook (#16462)

Marcin Gębala0c1f1ce183e9
diff --git a/saleor/graphql/meta/extra_methods.py b/saleor/graphql/meta/extra_methods.py
index 8653cfe1b0..b59dd87f88 100644
--- a/saleor/graphql/meta/extra_methods.py
+++ b/saleor/graphql/meta/extra_methods.py
@@ -2,7 +2,6 @@ from ...checkout.actions import call_checkout_event_for_checkout_info
from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ...core.utils.events import webhook_async_event_requires_sync_webhooks_to_trigger
from ...order.actions import call_order_event
-from ...product.models import Product, ProductVariant
from ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ...webhook.utils import get_webhooks_for_multiple_events
from ..core import ResolveInfo
@@ -147,9 +146,3 @@ TYPE_EXTRA_METHODS = {
"Warehouse": extra_warehouse_actions,
"Voucher": extra_voucher_actions,
}
-
-
-TYPE_EXTRA_PREFETCH = {
- "Product": Product.objects.prefetched_for_webhook,
- "ProductVariant": ProductVariant.objects.prefetched_for_webhook,
-}
diff --git a/saleor/graphql/meta/mutations/base.py b/saleor/graphql/meta/mutations/base.py
index e125f013d3..830837063b 100644
--- a/saleor/graphql/meta/mutations/base.py
+++ b/saleor/graphql/meta/mutations/base.py
@@ -19,7 +19,7 @@ from ...core import ResolveInfo
from ...core.mutations import BaseMutation
from ...core.utils import from_global_id_or_error
from ...payment.utils import metadata_contains_empty_key
-from ..extra_methods import TYPE_EXTRA_METHODS, TYPE_EXTRA_PREFETCH
+from ..extra_methods import TYPE_EXTRA_METHODS
from ..permissions import AccountPermissions
from ..types import ObjectWithMetadata
from .utils import get_valid_metadata_instance
@@ -249,9 +249,6 @@ class BaseMetadataMutation(BaseMutation):
def perform_model_extra_actions(cls, root, info: ResolveInfo, type_name, **data):
"""Run extra metadata method based on mutating model."""
if TYPE_EXTRA_METHODS.get(type_name):
- prefetch_method = TYPE_EXTRA_PREFETCH.get(type_name)
- if prefetch_method:
- data["qs"] = prefetch_method()
instance = cls.get_instance(info, **data)
TYPE_EXTRA_METHODS[type_name](instance, info, **data)
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index a76340277e..eee9aa5cbb 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -692,7 +692,7 @@ class ProductReorderAttributeValues(BaseReorderAttributeValuesMutation):
)
try:
- product = models.Product.objects.prefetched_for_webhook().get(pk=pk)
+ product = models.Product.objects.get(pk=pk)
except ObjectDoesNotExist:
raise ValidationError(
{
diff --git a/saleor/graphql/product/mutations/channels.py b/saleor/graphql/product/mutations/channels.py
index ad969054e8..f283890b19 100644
--- a/saleor/graphql/product/mutations/channels.py
+++ b/saleor/graphql/product/mutations/channels.py
@@ -369,7 +369,7 @@ class ProductChannelListingUpdate(BaseChannelListingMutation):
mark_products_in_channels_as_dirty,
{channel_id: {product.pk} for channel_id in modified_channel_ids},
)
- product = ProductModel.objects.prefetched_for_webhook().get(pk=product.pk)
+ product = ProductModel.objects.get(pk=product.pk)
manager = get_plugin_manager_promise(info.context).get()
cls.call_event(manager.product_updated, product)
diff --git a/saleor/graphql/product/mutations/product/product_create.py b/saleor/graphql/product/mutations/product/product_create.py
index 518c611fb3..af05cdc961 100644
--- a/saleor/graphql/product/mutations/product/product_create.py
+++ b/saleor/graphql/product/mutations/product/product_create.py
@@ -218,7 +218,7 @@ class ProductCreate(ModelMutation):
@classmethod
def post_save_action(cls, info: ResolveInfo, instance, _cleaned_input):
- product = models.Product.objects.prefetched_for_webhook().get(pk=instance.pk)
+ product = models.Product.objects.get(pk=instance.pk)
manager = get_plugin_manager_promise(info.context).get()
cls.call_event(manager.product_created, product)
diff --git a/saleor/graphql/product/mutations/product/product_update.py b/saleor/graphql/product/mutations/product/product_update.py
index 91c41c31a6..03e28fa86a 100644
--- a/saleor/graphql/product/mutations/product/product_update.py
+++ b/saleor/graphql/product/mutations/product/product_update.py
@@ -49,9 +49,7 @@ class ProductUpdate(ProductCreate, ModelWithExtRefMutation):
@classmethod
def post_save_action(cls, info: ResolveInfo, instance, cleaned_input):
- product = models.Product.objects.prefetched_for_webhook(single_object=True).get(
- pk=instance.pk
- )
+ product = models.Product.objects.get(pk=instance.pk)
channel_ids = set(
product.channel_listings.all().values_list("channel_id", flat=True)
)
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index d8cf8c4824..8e39116352 100644
--- a/saleor/product/tasks.py
+++ b/saleor/product/tasks.py
@@ -311,17 +311,13 @@ def update_products_search_vector_task():
def collection_product_updated_task(product_ids):
manager = get_plugins_manager(allow_replica=True)
products = list(
- Product.objects.using(settings.DATABASE_CONNECTION_REPLICA_NAME)
- .filter(id__in=product_ids)
- .prefetched_for_webhook(single_object=False)
+ Product.objects.using(settings.DATABASE_CONNECTION_REPLICA_NAME).filter(
+ id__in=product_ids
+ )
)
replica_products_count = len(products)
if replica_products_count != len(product_ids):
- products = list(
- Product.objects.filter(id__in=product_ids).prefetched_for_webhook(
- single_object=False
- )
- )
+ products = list(Product.objects.filter(id__in=product_ids))
if len(products) != replica_products_count:
logger.warning(
"collection_product_updated_task fetched %s products from replica, "
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index 6cc5129cef..763c03befa 100644
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -70,7 +70,7 @@ def delete_categories(categories_ids: list[Union[str, int]], manager):
def collect_categories_tree_products(category: "Category") -> "QuerySet[Product]":
"""Collect products from all levels in category tree."""
- products = category.products.prefetched_for_webhook(single_object=False)
+ products = category.products.all()
descendants = category.get_descendants()
for descendant in descendants:
products = products | descendant.products.all()