[REFACTOR] 優化資料庫查詢效能:在多個 Service 與 Controller 中加入 select 欄位限制,並新增租戶資料表索引 Migration。
This commit is contained in:
@@ -118,7 +118,7 @@ class PurchaseOrderController extends Controller
|
||||
public function create()
|
||||
{
|
||||
// 1. 獲取廠商(無關聯)
|
||||
$vendors = Vendor::all();
|
||||
$vendors = Vendor::select('id', 'name')->get();
|
||||
|
||||
// 2. 手動注入:獲取 Pivot 資料
|
||||
$vendorIds = $vendors->pluck('id')->toArray();
|
||||
@@ -379,7 +379,7 @@ class PurchaseOrderController extends Controller
|
||||
$order = PurchaseOrder::with(['items'])->findOrFail($id);
|
||||
|
||||
// 2. 獲取廠商與商品(與 create 邏輯一致)
|
||||
$vendors = Vendor::all();
|
||||
$vendors = Vendor::select('id', 'name')->get();
|
||||
$vendorIds = $vendors->pluck('id')->toArray();
|
||||
$pivots = DB::table('product_vendor')->whereIn('vendor_id', $vendorIds)->get();
|
||||
$productIds = $pivots->pluck('product_id')->unique()->toArray();
|
||||
|
||||
Reference in New Issue
Block a user