perf(bo): optimize product selection and association queries in BO controllers [AUD-PER-012]
This commit is contained in:
parent
29fa8a1b7d
commit
668aaba1ca
2 changed files with 25 additions and 10 deletions
|
|
@ -41,7 +41,10 @@ class DiscountsController extends Controller
|
|||
$this->authorize('create', Discount::class);
|
||||
|
||||
$discountTypes = DiscountType::cases();
|
||||
$existingProds = Product::all();
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
$selectedProds = [];
|
||||
|
||||
return view('bo.discounts.create', compact(
|
||||
|
|
@ -87,9 +90,14 @@ class DiscountsController extends Controller
|
|||
|
||||
$discountTypes = DiscountType::cases();
|
||||
|
||||
$existingProds = Product::query()->get();
|
||||
$selectedProds = $discount->products;
|
||||
$existingProds = $existingProds->diff($selectedProds);
|
||||
$selectedProds = $discount->products()
|
||||
->select(['products.id', 'products.name'])
|
||||
->get();
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->whereNotIn('id', $selectedProds->pluck('id'))
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('bo.discounts.edit', compact(
|
||||
'discount',
|
||||
|
|
|
|||
|
|
@ -160,7 +160,10 @@ class ProductsController extends Controller implements MassActions
|
|||
$ranges = Range::query()->pluck('name', 'id');
|
||||
$tags = Tag::query()->select('label', 'id', 'slug')->get();
|
||||
|
||||
$existingProds = Product::all();
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->orderBy('name')
|
||||
->get();
|
||||
$selectedProds = [];
|
||||
|
||||
return view('bo.products.create', compact(
|
||||
|
|
@ -215,7 +218,7 @@ class ProductsController extends Controller implements MassActions
|
|||
{
|
||||
$this->authorize('update', $product);
|
||||
|
||||
$product->load(['tags', 'products', 'inco']);
|
||||
$product->load(['tags', 'inco']);
|
||||
|
||||
$brands = ProductBrand::cases();
|
||||
$taxes = TaxRate::cases();
|
||||
|
|
@ -225,11 +228,15 @@ class ProductsController extends Controller implements MassActions
|
|||
$ranges = Range::query()->pluck('name', 'id');
|
||||
$tags = Tag::query()->select('label', 'id', 'slug')->get();
|
||||
|
||||
$existingProds = Product::query()
|
||||
->where('id', '!=', $product->id)
|
||||
$selectedProds = $product->products()
|
||||
->select(['products.id', 'products.name'])
|
||||
->get();
|
||||
$existingProds = Product::query()
|
||||
->select(['id', 'name'])
|
||||
->where('id', '!=', $product->id)
|
||||
->whereNotIn('id', $selectedProds->pluck('id'))
|
||||
->orderBy('name')
|
||||
->get();
|
||||
$selectedProds = $product->products;
|
||||
$existingProds = $existingProds->diff($selectedProds);
|
||||
|
||||
return view('bo.products.edit', compact(
|
||||
'product',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue