Performance Optimization Concept
1. Problem: Performance Drawbacks of the 3‑Layer Model
Issue
Description
-- ORM may generate:
SELECT o.*, oi.*, oi_u.*
FROM orders o
JOIN order_items oi ON oi.order_id = o.id
JOIN order_item_units oi_u ON oi_u.order_item_id = oi.id
WHERE o.id = :orderId;$order = orderRepository->find($id);
foreach ($order->getItems() as $item) {
$units = $item->getUnits(); // May trigger additional query per item
}2. Optimized Structure: Flatten Units into JSON
✅ What Changes
Component
Default Sylius (3-Layer)
Optimized Version (2-Layer with JSON)
Modified Entities
2.1. Mechanism: Full Lifecycle Control via Doctrine UoW
📦 PreFlush — Serialize & Detach
🚫 OnFlush — Skip Persisting Units
🔄 PostFlush — Restore for In-Memory Logic ( if direct access needed for example in behat tests )
✅ Why This Works
2.2. Rebuilding the Objects on postLoad
postLoad2.3. Metadata Configuration Overrides
Entity
Action Taken
4. Performance Gains



Summary
Last updated
Was this helpful?
