From b1cb9259da2bd4cf709a06b58d75258f0a664fb0 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 18:01:47 +0100 Subject: [PATCH 1/4] Re-use total to avoid duplicate count Signed-off-by: snipe --- app/Http/Controllers/Api/ReportsController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index fbeb78fc8..8761c9442 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -78,13 +78,14 @@ class ReportsController extends Controller ]; + $total = $actionlogs->count(); // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : app('api_offset_value'); + $offset = ($request->input('offset') > $total) ? $total : app('api_offset_value'); $limit = app('api_limit_value'); $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $order = ($request->input('order') == 'asc') ? 'asc' : 'desc'; - $total = $actionlogs->count(); + $actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get(); From 14c78d906548191d79c1db748514f475e2f1c9df Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 18:02:09 +0100 Subject: [PATCH 2/4] Use static for custom fields Signed-off-by: snipe --- app/Http/Transformers/ActionlogsTransformer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index ca0f6296e..51274a4d5 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -48,7 +48,12 @@ class ActionlogsTransformer public function transformActionlog (Actionlog $actionlog, $settings = null) { $icon = $actionlog->present()->icon(); + + static $custom_fields = false; + + if ($custom_fields === false) { $custom_fields = CustomField::all(); + } if ($actionlog->filename!='') { $icon = Helper::filetype_icon($actionlog->filename); From 1c1729854e7917d9fa763f6e3c168aff80d9cb8e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 18:02:22 +0100 Subject: [PATCH 3/4] Use statics for location, supplier, etc Signed-off-by: snipe --- .../Transformers/ActionlogsTransformer.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 51274a4d5..e760ba351 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -52,7 +52,7 @@ class ActionlogsTransformer static $custom_fields = false; if ($custom_fields === false) { - $custom_fields = CustomField::all(); + $custom_fields = CustomField::all(); } if ($actionlog->filename!='') { @@ -221,13 +221,30 @@ class ActionlogsTransformer */ public function changedInfo(array $clean_meta) - { $location = Location::withTrashed()->get(); - $supplier = Supplier::withTrashed()->get(); - $model = AssetModel::withTrashed()->get(); - $status = Statuslabel::withTrashed()->get(); - $company = Company::get(); + { + static $location = false; + static $supplier = false; + static $model = false; + static $status = false; + static $company = false; + if ($location === false) { + $location = Location::select('id', 'name')->withTrashed()->get(); + } + if ($supplier === false) { + $supplier = Supplier::select('id', 'name')->withTrashed()->get(); + } + if ($model === false) { + $model = AssetModel::select('id', 'name')->withTrashed()->get(); + } + if ($status === false) { + $status = Statuslabel::select('id', 'name')->withTrashed()->get(); + } + if ($company === false) { + $company = Company::select('id', 'name')->get(); + } + if(array_key_exists('rtd_location_id',$clean_meta)) { $oldRtd = $location->find($clean_meta['rtd_location_id']['old']); From 8ac3937bf43d7eb39d908f36d177f67473cfdff5 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 18:03:19 +0100 Subject: [PATCH 4/4] Commented model loading on asset model Signed-off-by: snipe --- app/Models/Asset.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index f31b87284..367f425a3 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -60,6 +60,12 @@ class Asset extends Depreciable */ protected $table = 'assets'; + /** + * Leaving this commented out, since we need to test further, but this would eager load the model relationship every single + * time the asset model is loaded. + */ + // protected $with = ['model']; + /** * Whether the model should inject it's identifier to the unique * validation rules before attempting validation. If this property