3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 03:45:24 +00:00

Fixed n+1 in top menu check

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-09-08 13:55:22 +01:00
parent 6b87c90e02
commit 14408ef18f

View File

@ -811,12 +811,11 @@ 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();
$total_owned = Asset::whereIn('model_id', $asset_models->pluck('id'))->count();
$avail = Asset::whereIn('model_id', $asset_models->pluck('id'))->whereNull('assigned_to')->count();
foreach ($asset_models as $asset_model) {
if ($avail < ($asset_model->min_amt) + $alert_threshold) {
if ($avail > 0) {
$percent = number_format((($avail / $total_owned) * 100), 0);