fix bug with keeping linking on updates

When moving the finding of linked places to the precomputation stage,
it was also moved before the statement where the linked_place_id was
removed from the linkee. The result was that the current linkee was
excluded when looking for a linked place on updates because it was
still linked to the boundary to be updated.

Fixed by allowing to either keep the linkage or change to an unlinked
place.
This commit is contained in:
Sarah Hoffmann 2022-05-23 10:11:28 +02:00
parent 4654701c10
commit 1d203fdb3c
2 changed files with 28 additions and 6 deletions

View File

@ -278,7 +278,7 @@ BEGIN
OR position(bnd_name in lower(name->'name')) > 0)
AND placex.class = 'place' AND placex.type = bnd.extratags->'place'
AND placex.osm_type = 'N'
AND placex.linked_place_id is null
AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26 -- needed to select the right index
AND placex.type != 'postcode'
AND ST_Covers(bnd.geometry, placex.geometry)
@ -294,7 +294,7 @@ BEGIN
WHERE placex.class = 'place' AND placex.osm_type = 'N'
AND placex.extratags ? 'wikidata' -- needed to select right index
AND placex.extratags->'wikidata' = bnd.extratags->'wikidata'
AND placex.linked_place_id is null
AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26
AND _st_covers(bnd.geometry, placex.geometry)
ORDER BY lower(name->'name') = bnd_name desc
@ -318,7 +318,7 @@ BEGIN
OR (bnd.rank_address = 0 and placex.rank_search = bnd.rank_search))
AND placex.osm_type = 'N'
AND placex.class = 'place'
AND placex.linked_place_id is null
AND (placex.linked_place_id is null or placex.linked_place_id = bnd.place_id)
AND placex.rank_search < 26 -- needed to select the right index
AND placex.type != 'postcode'
AND ST_Covers(bnd.geometry, placex.geometry)
@ -759,9 +759,6 @@ BEGIN
DELETE FROM place_addressline WHERE place_id = NEW.place_id;
result := deleteRoad(NEW.partition, NEW.place_id);
result := deleteLocationArea(NEW.partition, NEW.place_id, NEW.rank_search);
UPDATE placex set linked_place_id = null, indexed_status = 2
where linked_place_id = NEW.place_id;
-- update not necessary for osmline, cause linked_place_id does not exist
NEW.extratags := NEW.extratags - 'linked_place'::TEXT;
@ -770,6 +767,12 @@ BEGIN
linked_place := NEW.linked_place_id;
NEW.linked_place_id := OLD.linked_place_id;
-- Remove linkage, if we have computed a different new linkee.
UPDATE placex SET linked_place_id = null, indexed_status = 2
WHERE linked_place_id = NEW.place_id
and (linked_place is null or linked_place_id != linked_place);
-- update not necessary for osmline, cause linked_place_id does not exist
IF NEW.linked_place_id is not null THEN
NEW.token_info := null;
{% if debug %}RAISE WARNING 'place already linked to %', OLD.linked_place_id;{% endif %}

View File

@ -2,6 +2,25 @@
Feature: Updates of linked places
Tests that linked places are correctly added and deleted.
Scenario: Linking is kept when boundary is updated
Given the places
| osm | class | type | name | geometry |
| N1 | place | city | foo | 0 0 |
And the places
| osm | class | type | name | admin | geometry |
| R1 | boundary | administrative | foo | 8 | poly-area:0.1 |
When importing
Then placex contains
| object | linked_place_id |
| N1 | R1 |
When updating places
| osm | class | type | name | name+name:de | admin | geometry |
| R1 | boundary | administrative | foo | Dingens | 8 | poly-area:0.1 |
Then placex contains
| object | linked_place_id |
| N1 | R1 |
Scenario: Add linked place when linking relation is renamed
Given the places
| osm | class | type | name | geometry |