fix: commit orders immediately after creation during historical import
Orders were being flushed but only committed every 10 orders via the progress callback. With slow imports (~1.5 min/order), no commits happened before the first 10 orders, causing data loss if the import failed or was interrupted. Changes: - Add db.commit() after each successful order creation - Add db.rollback() on order creation failure to prevent corrupt state - Add db.commit() after order updates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -733,6 +733,7 @@ class LetzshopOrderService:
|
||||
pass
|
||||
|
||||
if needs_update:
|
||||
self.db.commit() # Commit update immediately
|
||||
stats["updated"] += 1
|
||||
else:
|
||||
stats["skipped"] += 1
|
||||
@@ -740,8 +741,10 @@ class LetzshopOrderService:
|
||||
# Create new order using unified service
|
||||
try:
|
||||
self.create_order(vendor_id, shipment)
|
||||
self.db.commit() # Commit each order immediately
|
||||
stats["imported"] += 1
|
||||
except Exception as e:
|
||||
self.db.rollback() # Rollback failed order
|
||||
stats["errors"] += 1
|
||||
stats["error_messages"].append(
|
||||
f"Shipment {shipment_id}: {str(e)}"
|
||||
|
||||
Reference in New Issue
Block a user