From 4476c9eea2a7ab7eaf38df61e21013c5a21405b4 Mon Sep 17 00:00:00 2001 From: "Aleksander V. Dyomin" Date: Mon, 5 Aug 2019 12:33:04 +0300 Subject: [PATCH 1/3] InvoiceReport: avoid additional queries in the result items loop (cherry picked from commit 9fd6ac0d7108a7e19faa5b3eae360974c1093d73) --- app/Ninja/Reports/InvoiceReport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Ninja/Reports/InvoiceReport.php b/app/Ninja/Reports/InvoiceReport.php index 1dce1b17b1b9..ddd410521cea 100644 --- a/app/Ninja/Reports/InvoiceReport.php +++ b/app/Ninja/Reports/InvoiceReport.php @@ -56,7 +56,7 @@ class InvoiceReport extends AbstractReport $clients = Client::scope() ->orderBy('name') ->withArchived() - ->with('contacts', 'user') + ->with('contacts', 'user', 'country', 'shipping_country') ->with(['invoices' => function ($query) use ($statusIds) { $query->invoices() ->withArchived() @@ -122,7 +122,7 @@ class InvoiceReport extends AbstractReport $invoice->po_number, $invoice->private_notes, $client->vat_number, - $invoice->user->getDisplayName(), + $client->user->getDisplayName(), trim(str_replace('
', ', ', $client->present()->address()), ', '), trim(str_replace('
', ', ', $client->present()->address(ADDRESS_SHIPPING)), ', '), ]; From de6919d37c8eb79ecc17b0518a96a6b927d39032 Mon Sep 17 00:00:00 2001 From: "Aleksander V. Dyomin" Date: Mon, 5 Aug 2019 12:33:56 +0300 Subject: [PATCH 2/3] Utils::getFromCache speedup via static variable cache (cherry picked from commit 7d65f8b1b726075626476501a4a58540e3aeb71f) --- app/Libraries/Utils.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 121e3cc5d6fd..5f2f61d543c0 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -22,6 +22,8 @@ use Nwidart\Modules\Facades\Module; class Utils { + protected static $cacheValues = []; + private static $weekdayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', ]; @@ -555,6 +557,9 @@ class Utils public static function getFromCache($id, $type) { + if (!empty(static::$cacheValues[$type]) && !empty(static::$cacheValues[$type][$id])) { + return static::$cacheValues[$type][$id]; + } $cache = Cache::get($type); if (! $cache) { @@ -567,7 +572,11 @@ class Utils return $item->id == $id; }); - return $data->first(); + $res = $data->first(); + if (!empty($res)) { + static::$cacheValues[$type][$id] = $res; + } + return $res; } public static function formatNumber($value, $currencyId = false, $precision = 0) From 67cb2b32151eb3c70838835dd6371bbd74acbee0 Mon Sep 17 00:00:00 2001 From: "Aleksander V. Dyomin" Date: Mon, 5 Aug 2019 13:16:03 +0300 Subject: [PATCH 3/3] TaxRateReport: avoid additional queries in the result items loop (cherry picked from commit d00d1e926628e5e0e83eb7570716eb3f332d6b27) --- app/Ninja/Reports/TaxRateReport.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Ninja/Reports/TaxRateReport.php b/app/Ninja/Reports/TaxRateReport.php index 4cc9df12468c..588432b3596e 100644 --- a/app/Ninja/Reports/TaxRateReport.php +++ b/app/Ninja/Reports/TaxRateReport.php @@ -31,7 +31,9 @@ class TaxRateReport extends AbstractReport ->withArchived() ->with('contacts', 'user') ->with(['invoices' => function ($query) { - $query->with('invoice_items') + $query + ->with('account', 'client') + ->with('invoice_items') ->withArchived() ->invoices() ->where('is_public', '=', true);