From b2d7003335c43f22fb517f19b7fcfc09e1fa9334 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 20 Dec 2020 10:44:19 +0100 Subject: [PATCH] Performance optimizations --- controllers/StockController.php | 1 - migrations/0123.sql | 11 +++++++++-- migrations/0124.sql | 10 ++++++++++ views/shoppinglist.blade.php | 18 +++++++++--------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/controllers/StockController.php b/controllers/StockController.php index 21cb16a1..1126b3f0 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -338,7 +338,6 @@ class StockController extends BaseController 'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'), 'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'), 'missingProducts' => $this->getStockService()->GetMissingProducts(), - 'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'), 'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name', 'COLLATE NOCASE'), 'selectedShoppingListId' => $listId, 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(), diff --git a/migrations/0123.sql b/migrations/0123.sql index 5fb74102..c9a66596 100644 --- a/migrations/0123.sql +++ b/migrations/0123.sql @@ -8,7 +8,10 @@ SELECT p.name AS product_name, plp.price * IFNULL(qucr.factor, 1.0) AS last_price_unit, plp.price * IFNULL(qucr.factor, 1.0) * sl.amount AS last_price_total, - st.name AS default_shopping_location_name + st.name AS default_shopping_location_name, + qu.name AS qu_name, + qu.name_plural AS qu_name_plural, + pg.name AS product_group_name FROM shopping_list sl LEFT JOIN products p ON sl.product_id = p.id @@ -19,4 +22,8 @@ LEFT JOIN quantity_unit_conversions_resolved qucr LEFT JOIN products_last_purchased plp ON sl.product_id = plp.product_id LEFT JOIN shopping_locations st - ON p.shopping_location_id = st.id; + ON p.shopping_location_id = st.id +LEFT JOIN quantity_units qu + ON sl.qu_id = qu.id +LEFT JOIN product_groups pg + ON p.product_group_id = pg.id; diff --git a/migrations/0124.sql b/migrations/0124.sql index f2905688..2f4180ba 100644 --- a/migrations/0124.sql +++ b/migrations/0124.sql @@ -109,3 +109,13 @@ BEGIN DELETE FROM battery_charge_cycles WHERE battery_id = OLD.id; END; + +CREATE INDEX ix_chores_performance1 ON chores ( + id, + active +); + +CREATE INDEX ix_batteries_performance1 ON batteries ( + id, + active +); diff --git a/views/shoppinglist.blade.php b/views/shoppinglist.blade.php index c2dcbb3d..3c8cd833 100644 --- a/views/shoppinglist.blade.php +++ b/views/shoppinglist.blade.php @@ -206,13 +206,13 @@ product_id)) data-toggle="tooltip" title="{{ $__t('Add %1$s of %2$s to stock', $listItem->amount . ' ' . $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural), FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name, $listItem->amount) }}" @endif> + @if(!empty($listItem->product_id)) data-toggle="tooltip" title="{{ $__t('Add %1$s of %2$s to stock', $listItem->amount . ' ' . $__n($listItem->amount, $listItem->qu_name, $listItem->qu_name_plural), $listItem->product_name, $listItem->amount) }}" @endif> - @if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}
@endif{!! nl2br($listItem->note) !!} + @if(!empty($listItem->product_id)) {{ $listItem->product_name }}
@endif{!! nl2br($listItem->note) !!} @if(!empty($listItem->product_id)) @php @@ -228,10 +228,10 @@ @endphp @endif amount }}> - {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural) }}@endif + {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, $listItem->qu_name, $listItem->qu_name_plural) }}@endif - @if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)->name }} @else {{ $__t('Ungrouped') }} @endif + @if(!empty($listItem->product_group_name)) {{ $listItem->product_group_name }} @else {{ $__t('Ungrouped') }} @endif @@ -349,13 +349,13 @@ @foreach($listItems as $listItem) - @if(!empty($listItem->product_id)) {{ FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->name }}
@endif{!! nl2br($listItem->note) !!} + @if(!empty($listItem->product_id)) {{ $listItem->product_name }}
@endif{!! nl2br($listItem->note) !!} - {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', $listItem->qu_id)->name_plural) }}@endif + {{ $listItem->amount }} @if(!empty($listItem->product_id)){{ $__n($listItem->amount, $listItem->qu_name, $listItem->qu_name_plural) }}@endif - @if(!empty(FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)) {{ FindObjectInArrayByPropertyValue($productGroups, 'id', FindObjectInArrayByPropertyValue($products, 'id', $listItem->product_id)->product_group_id)->name }} @else {{ $__t('Ungrouped') }} @endif + @if(!empty($listItem->product_group_name)) {{ $listItem->product_group_name }} @else {{ $__t('Ungrouped') }} @endif @include('components.userfields_tbody', array( @@ -372,8 +372,8 @@