From a4536670f07f67d776faa7b2c5b3b103431f3c8d Mon Sep 17 00:00:00 2001 From: Anders Gustafsson <34234789+anders-photowall@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:29:58 +0100 Subject: [PATCH] Add materialized view for category locale safe XML path (#529) --- migrations/000.612.sql | 32 ++++++++++++++++++++++++++++++++ migrations/000.613.sql | 31 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 migrations/000.612.sql create mode 100644 migrations/000.613.sql diff --git a/migrations/000.612.sql b/migrations/000.612.sql new file mode 100644 index 0000000..702eddf --- /dev/null +++ b/migrations/000.612.sql @@ -0,0 +1,32 @@ +DROP MATERIALIZED VIEW IF EXISTS mv_category_locale_safexmlpath_v2; +CREATE MATERIALIZED VIEW mv_category_locale_safexmlpath_v2 AS +SELECT + c.id AS category_id, + c.locale_id, + getsafexmlpath( + ( SELECT lower(array_to_string(array_agg(main_1.parent_name), '/'::text)) + FROM ( SELECT node.id, + ( SELECT category_texts_v2.name + FROM category_texts_v2 + WHERE ((category_texts_v2.locale_id = c.locale_id) AND (category_texts_v2.category_id = parent.id))) AS parent_name + FROM categories_v2_lft_rgt node, + categories_v2_lft_rgt parent + WHERE ((node.lft >= parent.lft) AND (node.lft <= parent.rgt) AND (node.id = c.id)) + ORDER BY parent.lft) main_1 + GROUP BY main_1.id), + 2 + ) AS safe_xml_path +FROM ( + SELECT c_1.id, + s.id AS locale_id + FROM locales s + JOIN category_texts_v2 s_t ON s.id = s_t.locale_id + JOIN categories_v2_lft_rgt c_1 ON s_t.category_id = c_1.id +) c; + +CREATE UNIQUE INDEX ON mv_category_locale_safexmlpath_v2 (category_id, locale_id); +CREATE INDEX ON mv_category_locale_safexmlpath_v2 (locale_id, safe_xml_path); + +COMMENT ON MATERIALIZED VIEW mv_category_locale_safexmlpath_v2 IS 'Materialized view for fast lookup of category id from localized safe xml path and locale. Path construction logic mirrors v_esales_categorytree_i18n_unmaterialized but additionally applies the getsafexmlpath(..., 2) function.'; + +ALTER MATERIALIZED VIEW mv_category_locale_safexmlpath_v2 OWNER TO Photowall; diff --git a/migrations/000.613.sql b/migrations/000.613.sql new file mode 100644 index 0000000..dfc8f43 --- /dev/null +++ b/migrations/000.613.sql @@ -0,0 +1,31 @@ +DROP MATERIALIZED VIEW IF EXISTS mv_category_locale_safexmlpath; +CREATE MATERIALIZED VIEW mv_category_locale_safexmlpath AS +SELECT + c.id AS category_id, + c.locale_id, + getsafexmlpath( + ( SELECT lower(array_to_string(array_agg(main_1.parent_name), '/'::text)) + FROM ( SELECT node.id, + ( SELECT category_texts.name + FROM category_texts + WHERE ((category_texts.locale_id = c.locale_id) AND (category_texts.category_id = parent.id))) AS parent_name + FROM categories node, + categories parent + WHERE ((node.lft >= parent.lft) AND (node.lft <= parent.rgt) AND (node.id = c.id)) + ORDER BY parent.lft) main_1 + GROUP BY main_1.id), + 2 + ) AS safe_xml_path +FROM ( + SELECT c_1.id, + s.id AS locale_id + FROM locales s + JOIN category_texts s_t ON s.id = s_t.locale_id + JOIN categories c_1 ON s_t.category_id = c_1.id +) c; + +CREATE UNIQUE INDEX ON mv_category_locale_safexmlpath (category_id, locale_id); +CREATE INDEX ON mv_category_locale_safexmlpath (locale_id, safe_xml_path); + +COMMENT ON MATERIALIZED VIEW IS 'Materialized view for fast lookup of category id from localized safe xml path and locale. Path construction logic mirrors v_esales_categorytree_i18n_unmaterialized but additionally applies the getsafexmlpath(..., 2) function.'; +ALTER MATERIALIZED VIEW mv_category_locale_safexmlpath OWNER TO Photowall;