Add materialized view for category locale safe XML path (#529)

This commit is contained in:
Anders Gustafsson
2026-03-03 10:29:58 +01:00
committed by GitHub
parent 261aea127a
commit a4536670f0
2 changed files with 63 additions and 0 deletions
+32
View File
@@ -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;
+31
View File
@@ -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;