A free open source IT asset/license management system
First stab at handling the n+1 issue on licenses
snipe368ac5b85d8d
diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.phpindex ff58362f6c..965112613e 100644--- a/app/Http/Controllers/Api/LicensesController.php+++ b/app/Http/Controllers/Api/LicensesController.php@@ -21,7 +21,7 @@ class LicensesController extends Controllerpublic function index(Request $request){$this->authorize('view', License::class);- $licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer', 'supplier'));+ $licenses = Company::scopeCompanyables(License::with('company', 'licenseseats', 'manufacturer', 'supplier')->withCount('licenseseats'));if ($request->has('search')) {$licenses = $licenses->TextSearch($request->input('search'));diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.phpindex f3644dd4d0..2c94721100 100644--- a/app/Http/Transformers/LicensesTransformer.php+++ b/app/Http/Transformers/LicensesTransformer.php@@ -33,16 +33,14 @@ class LicensesTransformer'notes' => e($license->notes),'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),'total_seats' => (int) $license->seats,- 'next_seat' => ($license->freeSeat()) ? (int) $license->freeSeat()->id : null,- 'remaining_qty' => (int) $license->remaincount(),- 'min_qty' => $license->remaincount(),+ 'remaining_qty' => (int) ($license->seats - $license->licenseseats_count),'license_name' => e($license->license_name),'license_email' => e($license->license_email),'maintained' => ($license->maintained == 1) ? true : false,'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null,'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),- 'user_can_checkout' => (bool) ($license->remaincount() > 0),+ 'user_can_checkout' => (bool) (($license->seats - $license->licenseseats_count) > 0),];$permissions_array['available_actions'] = [