diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index fbeb78fc8f..8761c9442b 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(); diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index ca0f6296ee..e760ba351a 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(); - $custom_fields = CustomField::all(); + + static $custom_fields = false; + + if ($custom_fields === false) { + $custom_fields = CustomField::all(); + } if ($actionlog->filename!='') { $icon = Helper::filetype_icon($actionlog->filename); @@ -216,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']); diff --git a/app/Models/Asset.php b/app/Models/Asset.php index f31b872841..367f425a38 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