Enhance SQL query for character region filtering: Updated the query to use a recursive common table expression (CTE) for retrieving region IDs, allowing for more comprehensive region hierarchy handling. This change improves the accuracy of character selection based on regional relationships while maintaining existing filtering criteria.

This commit is contained in:
Torsten Schulz (local)
2026-02-05 23:59:20 +01:00
parent 1e565e6dd9
commit 4baf88b0cf
2 changed files with 18 additions and 2 deletions

View File

@@ -884,7 +884,15 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#"
) AS rn
FROM needed_to_fill AS rtf
JOIN falukant_data.character AS ch
ON ch.region_id = rtf.region_id
ON ch.region_id IN (
WITH RECURSIVE region_tree AS (
SELECT id FROM falukant_data.region WHERE id = rtf.region_id
UNION ALL
SELECT r2.id FROM falukant_data.region r2
JOIN region_tree rt ON r2.parent_id = rt.id
)
SELECT id FROM region_tree
)
AND ch.user_id IS NULL
AND ch.birthdate <= NOW() - INTERVAL '21 days'
AND ch.title_of_nobility IN (

View File

@@ -883,7 +883,15 @@ pub const QUERY_PROCESS_EXPIRED_AND_FILL: &str = r#"
) AS rn
FROM needed_to_fill AS rtf
JOIN falukant_data.character AS ch
ON ch.region_id = rtf.region_id
ON ch.region_id IN (
WITH RECURSIVE region_tree AS (
SELECT id FROM falukant_data.region WHERE id = rtf.region_id
UNION ALL
SELECT r2.id FROM falukant_data.region r2
JOIN region_tree rt ON r2.parent_id = rt.id
)
SELECT id FROM region_tree
)
AND ch.user_id IS NULL
AND ch.birthdate <= NOW() - INTERVAL '21 days'
AND ch.title_of_nobility IN (