mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
* Stock-Overview: Reduce amount of database queries and FindObjectInArray()-calls * Speed-up stock_current by improving products_resolved and creating indices. * Review Co-authored-by: Bernd Bestel <bernd@berrnd.de>
30 lines
609 B
SQL
30 lines
609 B
SQL
CREATE INDEX ix_products_performance1 ON products (
|
|
parent_product_id
|
|
);
|
|
|
|
CREATE INDEX ix_products_performance2 ON products (
|
|
CASE WHEN parent_product_id IS NULL THEN id ELSE parent_product_id END,
|
|
active
|
|
);
|
|
|
|
CREATE INDEX ix_stock_performance1 ON stock (
|
|
product_id,
|
|
open,
|
|
best_before_date,
|
|
amount
|
|
);
|
|
|
|
DROP VIEW products_resolved;
|
|
CREATE VIEW products_resolved
|
|
AS
|
|
SELECT
|
|
CASE
|
|
WHEN p.parent_product_id IS NULL THEN
|
|
p.id
|
|
ELSE
|
|
p.parent_product_id
|
|
END AS parent_product_id,
|
|
p.id as sub_product_id
|
|
FROM products p
|
|
WHERE p.active = 1;
|