Merge pull request #14164 from marcusmoore/bug/sc-20686

Avoid unnecessarily hydrating models on asset show page
This commit is contained in:
snipe 2024-01-25 00:20:30 +00:00 committed by GitHub
commit 45b253a57d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -288,7 +288,7 @@ class AssetModelsController extends Controller
public function show($modelId = null)
{
$this->authorize('view', AssetModel::class);
$model = AssetModel::withTrashed()->find($modelId);
$model = AssetModel::withTrashed()->withCount('assets')->find($modelId);
if (isset($model->id)) {
return view('models/view', compact('model'));

View file

@ -43,7 +43,7 @@
</span>
<span class="hidden-xs hidden-sm">
{{ trans('general.assets') }}
{!! (($model->assets) && ($model->assets->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($model->assets->count()).'</badge>' : '' !!}
{!! (($model->assets_count) && ($model->assets_count > 0 )) ? '<badge class="badge badge-secondary">'.number_format($model->assets_count).'</badge>' : '' !!}
</span>
</a>
</li>
@ -342,7 +342,7 @@
@endcan
@can('delete', \App\Models\AssetModel::class)
@if ($model->assets->count() > 0)
@if ($model->assets_count > 0)
<div class="col-md-12" style="padding-bottom: 5px;">
<button class="btn btn-block btn-sm btn-danger hidden-print disabled" data-tooltip="true" data-placement="top" data-title="{{ trans('general.cannot_be_deleted') }}">{{ trans('general.delete') }}</button>