BUGFIX: Route concurrency data is wiped after route member updates (#1239)

This PR is a bugfix for the `transportation_name` layer.  Currently, the updates process does not work, as noted by @zstadler in #1230.  The issue is that the computed `concurrency_index` column in `osm_route_member` is never updated after the initial updates.  Therefore, whenever route member ways are updated, they will lose their route concurrency index, and hence route concurrencies will be lost in the `transportation_name` tiles.  This PR adds the missing concurrency index update code to the transportation/network update triggers.

This PR as written also incorporates the fixes in #1230 and #1233.

The following SQL is a unit test to demonstrate that these triggers work correctly:

```
select count(*) from osm_route_member where concurrency_index > 5;
select count(*) from osm_transportation_name_network where route_6 is not null;

update osm_route_member set concurrency_index=NULL where concurrency_index > 5;

select count(*) from osm_route_member where concurrency_index > 5;
select count(*) from osm_transportation_name_network where route_6 is not null;
```

If working correctly, both pairs of `count(*)` values should return the same pair of numbers.
This commit is contained in:
Brian Sperlongano
2021-09-21 06:56:25 -04:00
committed by GitHub
parent 6f0ab57547
commit 88389f2a2c
2 changed files with 50 additions and 20 deletions

View File

@@ -60,13 +60,16 @@ BEGIN
JOIN transportation_name.network_changes AS c ON
r.osm_id = c.osm_id;
UPDATE
osm_route_member AS r
SET network_type = osm_route_member_network_type(network)
FROM transportation_name.network_changes AS c
WHERE network != ''
AND network_type IS DISTINCT FROM osm_route_member_network_type(network)
AND r.member = c.osm_id;
INSERT INTO osm_route_member (id, network_type, concurrency_index)
SELECT
id,
osm_route_member_network_type(network) AS network_type,
DENSE_RANK() over (PARTITION BY member ORDER BY network_type, network, LENGTH(ref), ref) AS concurrency_index
FROM osm_route_member rm
WHERE rm.member IN
(SELECT DISTINCT osm_id FROM transportation_name.network_changes)
ON CONFLICT (id) DO UPDATE SET concurrency_index = EXCLUDED.concurrency_index;
END;
$$ LANGUAGE plpgsql;
@@ -82,6 +85,7 @@ CREATE INDEX IF NOT EXISTS osm_highway_linestring_gen_z11_osm_id_idx ON osm_high
ALTER TABLE osm_route_member ADD COLUMN IF NOT EXISTS concurrency_index int;
-- One-time load of concurrency indexes; updates occur via trigger
INSERT INTO osm_route_member (id, concurrency_index)
SELECT
id,