mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Merge pull request #14777 from snipe/fixes/reportscontroller_optimizations
Reports controller query optimizations
This commit is contained in:
commit
fceba13b03
|
@ -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
|
// 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');
|
$limit = app('api_limit_value');
|
||||||
|
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||||
$order = ($request->input('order') == 'asc') ? 'asc' : 'desc';
|
$order = ($request->input('order') == 'asc') ? 'asc' : 'desc';
|
||||||
$total = $actionlogs->count();
|
|
||||||
|
|
||||||
$actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();
|
$actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,12 @@ class ActionlogsTransformer
|
||||||
public function transformActionlog (Actionlog $actionlog, $settings = null)
|
public function transformActionlog (Actionlog $actionlog, $settings = null)
|
||||||
{
|
{
|
||||||
$icon = $actionlog->present()->icon();
|
$icon = $actionlog->present()->icon();
|
||||||
|
|
||||||
|
static $custom_fields = false;
|
||||||
|
|
||||||
|
if ($custom_fields === false) {
|
||||||
$custom_fields = CustomField::all();
|
$custom_fields = CustomField::all();
|
||||||
|
}
|
||||||
|
|
||||||
if ($actionlog->filename!='') {
|
if ($actionlog->filename!='') {
|
||||||
$icon = Helper::filetype_icon($actionlog->filename);
|
$icon = Helper::filetype_icon($actionlog->filename);
|
||||||
|
@ -216,13 +221,30 @@ class ActionlogsTransformer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function changedInfo(array $clean_meta)
|
public function changedInfo(array $clean_meta)
|
||||||
{ $location = Location::withTrashed()->get();
|
{
|
||||||
$supplier = Supplier::withTrashed()->get();
|
static $location = false;
|
||||||
$model = AssetModel::withTrashed()->get();
|
static $supplier = false;
|
||||||
$status = Statuslabel::withTrashed()->get();
|
static $model = false;
|
||||||
$company = Company::get();
|
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)) {
|
if(array_key_exists('rtd_location_id',$clean_meta)) {
|
||||||
|
|
||||||
$oldRtd = $location->find($clean_meta['rtd_location_id']['old']);
|
$oldRtd = $location->find($clean_meta['rtd_location_id']['old']);
|
||||||
|
|
|
@ -60,6 +60,12 @@ class Asset extends Depreciable
|
||||||
*/
|
*/
|
||||||
protected $table = 'assets';
|
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
|
* Whether the model should inject it's identifier to the unique
|
||||||
* validation rules before attempting validation. If this property
|
* validation rules before attempting validation. If this property
|
||||||
|
|
Loading…
Reference in a new issue