-
-
Notifications
You must be signed in to change notification settings - Fork 8
bug: Area elements do not get recalculated on change of area bounds. #73
Description
Problem Summary
When a community boundary (geo_json) is redefined, the "Maintain" tab continues to show linting issues for elements that are now outside the new bounds.
Root Cause
The linting issues are fetched via an RPC call to get_element_issues which queries the element_issue table joined with the area_element table. However, the SQL queries don't filter out soft-deleted area_element records.
Flow of the Bug
-
Initial State: Element A is inside Community X's bounds →
area_elementrecord exists linking Element A to Community X -
Boundary Change: You update Community X's geo_json, and Element A is now outside the new bounds
-
Correct Behavior:
patch_tags()inarea.rscallsgenerate_mapping()which correctly marks thearea_elementrecord as deleted by settingdeleted_at = NOW() -
Bug: The
get_element_issuesRPC still returns Element A's issues because the SQL join doesn't filter fordeleted_at IS NULL
Location of Bug
File: btcmap-api/src/db/element_issue/blocking_queries.rs
Affected Functions:
select_ordered_by_severity()(lines 80-125)select_count()(lines 142-189)
The Problematic Code
In select_ordered_by_severity() (line 87-93):
let area_join = match area_id {
662 => "".into(),
_ => format!(
"INNER JOIN {area_element_table} ae ON ae.element_id = ei.element_id AND ae.area_id = {area_id}",
area_element_table = db::area_element::schema::TABLE_NAME
)
};Missing: AND ae.deleted_at IS NULL
In select_count() (line 148-153):
let area_join = match area_id {
662 => "".into(),
_ => format!(
"INNER JOIN {area_element_table} ae ON ae.element_id = ei.element_id AND ae.area_id = {area_id}",
area_element_table = db::area_element::schema::TABLE_NAME
)
};Missing: Same issue - no deleted_at filter
The Fix
Add AND ae.deleted_at IS NULL to both area_join clauses:
let area_join = match area_id {
662 => "".into(),
_ => format!(
"INNER JOIN {area_element_table} ae ON ae.element_id = ei.element_id AND ae.area_id = {area_id} AND ae.deleted_at IS NULL",
area_element_table = db::area_element::schema::TABLE_NAME
)
};Files to Modify
btcmap-api/src/db/element_issue/blocking_queries.rs- Line 89-93: Update
area_joininselect_ordered_by_severity() - Line 150-153: Update
area_joininselect_count()
- Line 89-93: Update
Impact
After this fix, when a community boundary is updated:
- Elements outside the new bounds will have their
area_elementrecords soft-deleted - The maintain tab queries will correctly exclude these elements' issues
- Users will only see issues for elements actually within the community's current bounds