3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 12:35:40 +00:00

Merge pull request #17823 from grokability/#17822-fix-n+1-in-topmenu

Fixed #17822 - n+1 in top menu check
This commit is contained in:
snipe
2025-09-08 14:33:47 +01:00
committed by GitHub

View File

@ -748,7 +748,7 @@ class Helper
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
$accessories = Accessory::withCount('checkouts as checkouts_count')->whereNotNull('min_amt')->get();
$components = Component::whereNotNull('min_amt')->get();
$asset_models = AssetModel::where('min_amt', '>', 0)->get();
$asset_models = AssetModel::where('min_amt', '>', 0)->with('assets')->get();
$licenses = License::where('min_amt', '>', 0)->get();
$items_array = [];
@ -811,11 +811,13 @@ class Helper
}
}
foreach ($asset_models as $asset_model){
$asset = new Asset();
$total_owned = $asset->where('model_id', '=', $asset_model->id)->count();
$avail = $asset->where('model_id', '=', $asset_model->id)->whereNull('assigned_to')->count();
foreach ($asset_models as $asset_model) {
$total_owned = $asset_model->assets->count();
$avail = $asset_model->assets->whereNull('assets.assigned_to')->count();
if ($avail < ($asset_model->min_amt) + $alert_threshold) {
if ($avail > 0) {