Make demo purge independent of Elasticsearch

This commit is contained in:
2026-04-06 02:38:02 +02:00
parent 90e24976df
commit dbc9fe87c6

View File

@@ -94,6 +94,10 @@ class Command(BaseCommand):
def _purge_products(self, *, dry_run: bool, keep_only_idea_products: bool) -> int: def _purge_products(self, *, dry_run: bool, keep_only_idea_products: bool) -> int:
from oscar.core.loading import get_model from oscar.core.loading import get_model
from oscar_elasticsearch.search.signal_handlers import (
deregister_signal_handlers,
register_signal_handlers,
)
Product = get_model("catalogue", "Product") Product = get_model("catalogue", "Product")
products = Product.objects.all() products = Product.objects.all()
@@ -110,11 +114,20 @@ class Command(BaseCommand):
removed = 0 removed = 0
iterable = candidates if isinstance(candidates, list) else list(candidates) iterable = candidates if isinstance(candidates, list) else list(candidates)
if dry_run:
for product in iterable: for product in iterable:
removed += 1 removed += 1
self.stdout.write( self.stdout.write(
f"PRODUCT {'[dry-run] ' if dry_run else ''}delete id={product.id} title={product.title}" f"PRODUCT [dry-run] delete id={product.id} title={product.title}"
) )
if not dry_run: return removed
product.delete()
deregister_signal_handlers()
try:
for product in iterable:
removed += 1
self.stdout.write(f"PRODUCT delete id={product.id} title={product.title}")
product.delete()
finally:
register_signal_handlers()
return removed return removed