mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Optimized StockService->GetProductDetails performance (fixes #2283)
This commit is contained in:
parent
57ccb8645e
commit
fd7e24b7d1
55
changelog/71_UNRELEASED_xxxx-xx-xx.md
Normal file
55
changelog/71_UNRELEASED_xxxx-xx-xx.md
Normal file
@ -0,0 +1,55 @@
|
||||
> ⚠️ xxxBREAKING CHANGESxxx
|
||||
|
||||
> ❗ xxxImportant upgrade informationXXX
|
||||
|
||||
### New feature: xxxx
|
||||
|
||||
- xxx
|
||||
|
||||
### Stock
|
||||
|
||||
- Performance fixes related to the stock overview and purchase/consume/inventory/transfer page
|
||||
|
||||
### Shopping list
|
||||
|
||||
- xxx
|
||||
|
||||
### Recipes
|
||||
|
||||
- xxx
|
||||
|
||||
### Meal plan
|
||||
|
||||
- xxx
|
||||
|
||||
### Chores
|
||||
|
||||
- xxx
|
||||
|
||||
### Calendar
|
||||
|
||||
- xxx
|
||||
|
||||
### Tasks
|
||||
|
||||
- xxx
|
||||
|
||||
### Batteries
|
||||
|
||||
- xxx
|
||||
|
||||
### Equipment
|
||||
|
||||
- xxx
|
||||
|
||||
### Userfields
|
||||
|
||||
- xxx
|
||||
|
||||
### General
|
||||
|
||||
- xxx
|
||||
|
||||
### API
|
||||
|
||||
- Fixed performance issues on the endpoint `/stock/products/{productId}`
|
@ -3,7 +3,7 @@ DROP VIEW products_current_price;
|
||||
|
||||
CREATE VIEW products_last_purchased
|
||||
AS
|
||||
select
|
||||
SELECT
|
||||
1 AS id, -- Dummy, LessQL needs an id column
|
||||
sl.product_id,
|
||||
sl.amount,
|
||||
@ -14,20 +14,20 @@ select
|
||||
sl.shopping_location_id
|
||||
FROM stock_log sl
|
||||
JOIN (
|
||||
SELECT
|
||||
s1.product_id,
|
||||
MAX(s1.id) max_stock_id
|
||||
FROM stock_log s1
|
||||
JOIN (
|
||||
SELECT
|
||||
s.product_id,
|
||||
MAX(s.purchased_date) max_purchased_date
|
||||
FROM stock_log s
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s.product_id) sp2
|
||||
ON s1.product_id = sp2.product_id
|
||||
AND s1.purchased_date = sp2.max_purchased_date
|
||||
SELECT
|
||||
s1.product_id,
|
||||
MAX(s1.id) max_stock_id
|
||||
FROM stock_log s1
|
||||
JOIN (
|
||||
SELECT
|
||||
s.product_id,
|
||||
MAX(s.purchased_date) max_purchased_date
|
||||
FROM stock_log s
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s.product_id) sp2
|
||||
ON s1.product_id = sp2.product_id
|
||||
AND s1.purchased_date = sp2.max_purchased_date
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s1.product_id) sp3
|
||||
|
@ -4,7 +4,7 @@ AS
|
||||
Returns stock_id's which have been edited manually
|
||||
*/
|
||||
SELECT DISTINCT sl_add.stock_id
|
||||
fROM stock_log sl_add
|
||||
FROM stock_log sl_add
|
||||
JOIN stock_log sl_edit
|
||||
ON sl_add.stock_id = sl_edit.stock_id
|
||||
AND sl_edit.transaction_type = 'stock-edit-new'
|
||||
|
@ -15,7 +15,7 @@ GROUP BY s.product_id;
|
||||
DROP VIEW products_last_purchased;
|
||||
CREATE VIEW products_last_purchased
|
||||
AS
|
||||
select
|
||||
SELECT
|
||||
1 AS id, -- Dummy, LessQL needs an id column
|
||||
sl.product_id,
|
||||
sl.amount,
|
||||
@ -26,20 +26,20 @@ select
|
||||
sl.shopping_location_id
|
||||
FROM stock_log sl
|
||||
JOIN (
|
||||
SELECT
|
||||
s1.product_id,
|
||||
MAX(s1.id) max_stock_id
|
||||
FROM stock_log s1
|
||||
JOIN (
|
||||
SELECT
|
||||
s.product_id,
|
||||
MAX(s.purchased_date) max_purchased_date
|
||||
FROM stock_log s
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s.product_id) sp2
|
||||
ON s1.product_id = sp2.product_id
|
||||
AND s1.purchased_date = sp2.max_purchased_date
|
||||
SELECT
|
||||
s1.product_id,
|
||||
MAX(s1.id) max_stock_id
|
||||
FROM stock_log s1
|
||||
JOIN (
|
||||
SELECT
|
||||
s.product_id,
|
||||
MAX(s.purchased_date) max_purchased_date
|
||||
FROM stock_log s
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s.product_id) sp2
|
||||
ON s1.product_id = sp2.product_id
|
||||
AND s1.purchased_date = sp2.max_purchased_date
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s1.product_id) sp3
|
||||
|
48
migrations/0221.sql
Normal file
48
migrations/0221.sql
Normal file
@ -0,0 +1,48 @@
|
||||
CREATE VIEW products_last_price
|
||||
AS
|
||||
SELECT
|
||||
product_id,
|
||||
MAX(purchased_date) AS purchased_date,
|
||||
price -- Bare column, ref https://www.sqlite.org/lang_select.html#bare_columns_in_an_aggregate_query
|
||||
FROM stock_log
|
||||
WHERE transaction_type IN ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
AND IFNULL(price, 0) > 0
|
||||
AND IFNULL(amount, 0) > 0
|
||||
AND undone = 0
|
||||
GROUP BY product_id;
|
||||
|
||||
DROP VIEW products_last_purchased;
|
||||
CREATE VIEW products_last_purchased
|
||||
AS
|
||||
SELECT
|
||||
1 AS id, -- Dummy, LessQL needs an id column
|
||||
sl.product_id,
|
||||
sl.amount,
|
||||
sl.best_before_date,
|
||||
sl.purchased_date,
|
||||
IFNULL(plp.price, 0) AS price,
|
||||
sl.location_id,
|
||||
sl.shopping_location_id
|
||||
FROM stock_log sl
|
||||
JOIN (
|
||||
SELECT
|
||||
s1.product_id,
|
||||
MAX(s1.id) max_stock_id
|
||||
FROM stock_log s1
|
||||
JOIN (
|
||||
SELECT
|
||||
s.product_id,
|
||||
MAX(s.purchased_date) max_purchased_date
|
||||
FROM stock_log s
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s.product_id) sp2
|
||||
ON s1.product_id = sp2.product_id
|
||||
AND s1.purchased_date = sp2.max_purchased_date
|
||||
WHERE undone = 0
|
||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||
GROUP BY s1.product_id) sp3
|
||||
ON sl.product_id = sp3.product_id
|
||||
AND sl.id = sp3.max_stock_id
|
||||
LEFT JOIN products_last_price plp
|
||||
ON sl.product_id = plp.product_id;
|
Loading…
x
Reference in New Issue
Block a user