Skip to content

Commit 1c4ce75

Browse files
committed
New nodes and ways can't have existing parents
New nodes or ways (ie with version=1) can't have parent ways or relations. So we don't have to add them to the list of "changed nodes" or "changed ways" to trigger re-processing of changed parents. This will save us a whole lot of effort looking for parents that are never there. Note that we are checking for version != 1. In the (unlikely) case that there are no versions in the input file (making version == 0), everything will work as before.
1 parent fd531a0 commit 1c4ce75

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/osmdata.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ void osmdata_t::node(osmium::Node const &node)
6565
} else {
6666
m_output->node_delete(node.id());
6767
}
68-
m_changed_nodes.push_back(node.id());
68+
69+
// Version 1 means this is a new node, so there can't be an existing
70+
// way or relation referencing it, so we don't have to add that node
71+
// to the list of changed nodes. If the input data doesn't contain
72+
// object versions this will still work, because then the version is 0.
73+
if (node.version() != 1) {
74+
m_changed_nodes.push_back(node.id());
75+
}
6976
} else if (has_tags_or_attrs) {
7077
m_output->node_add(node);
7178
}
@@ -103,7 +110,14 @@ void osmdata_t::way(osmium::Way &way)
103110
} else {
104111
m_output->way_delete(way.id());
105112
}
106-
m_changed_ways.push_back(way.id());
113+
114+
// Version 1 means this is a new way, so there can't be an existing
115+
// relation referencing it, so we don't have to add that way to the
116+
// list of changed ways. If the input data doesn't contain object
117+
// versions this will still work, because then the version is 0.
118+
if (way.version() != 1) {
119+
m_changed_ways.push_back(way.id());
120+
}
107121
} else if (has_tags_or_attrs) {
108122
m_output->way_add(&way);
109123
}

tests/bdd/flex/way-change.feature

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Feature: Changing ways in a flex database
1010
Scenario Outline:
1111
Given the OSM data:
1212
"""
13+
w10 v1 dV Tt1=yes Nn10,n11
1314
w11 v1 dV Tt1=yes Nn12,n13
1415
w12 v1 dV Tt2=yes Nn14,n15
1516
w13 v1 dV Ttboth=yes Nn16,n17
1617
w14 v1 dV Ttboth=yes Nn18,n19
17-
w10 v1 dV Tt1=yes Nn10,n11
1818
r30 v1 dV Tt=ag Mw10@mark,w11@,w12@mark,w13@,w14@mark
1919
"""
2020
When running osm2pgsql flex with parameters
@@ -56,18 +56,18 @@ Feature: Changing ways in a flex database
5656

5757
Examples:
5858
| input | num_w10 |
59-
| w10 v1 dV Tt2=yes Nn10,n11 | 0 |
60-
| w10 v1 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
59+
| w10 v2 dV Tt2=yes Nn10,n11 | 0 |
60+
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
6161

6262

6363
Scenario Outline: change way from t2
6464
Given the OSM data
6565
"""
66+
w10 v1 dV Tt2=yes Nn10,n11
6667
w11 v1 dV Tt1=yes Nn12,n13
6768
w12 v1 dV Tt2=yes Nn14,n15
6869
w13 v1 dV Ttboth=yes Nn16,n17
6970
w14 v1 dV Ttboth=yes Nn18,n19
70-
w10 v1 dV Tt2=yes Nn10,n11
7171
r30 v1 dV Tt=ag Mw10@mark,w11@,w12@mark,w13@,w14@mark
7272
"""
7373
When running osm2pgsql flex with parameters
@@ -109,18 +109,18 @@ Feature: Changing ways in a flex database
109109

110110
Examples:
111111
| input | num_w10 |
112-
| w10 v1 dV Tt1=yes Nn10,n11 | 0 |
113-
| w10 v1 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
112+
| w10 v2 dV Tt1=yes Nn10,n11 | 0 |
113+
| w10 v2 dV Tt1=yes,t2=yes Nn10,n11 | 1 |
114114

115115

116116
Scenario Outline: change way from t1 and t2
117117
Given the OSM data
118118
"""
119+
w10 v1 dV Tt1=yes,t2=yes Nn10,n11
119120
w11 v1 dV Tt1=yes Nn12,n13
120121
w12 v1 dV Tt2=yes Nn14,n15
121122
w13 v1 dV Ttboth=yes Nn16,n17
122123
w14 v1 dV Ttboth=yes Nn18,n19
123-
w10 v1 dV Tt1=yes,t2=yes Nn10,n11
124124
r30 v1 dV Tt=ag Mw10@mark,w11@,w12@mark,w13@,w14@mark
125125
"""
126126
When running osm2pgsql flex with parameters
@@ -166,18 +166,18 @@ Feature: Changing ways in a flex database
166166

167167
Examples:
168168
| input | num_t1 | num_t2 |
169-
| w10 v1 dV Tt1=yes Nn10,n11 | 1 | 0 |
170-
| w10 v1 dV Tt2=yes Nn10,n11 | 0 | 1 |
169+
| w10 v2 dV Tt1=yes Nn10,n11 | 1 | 0 |
170+
| w10 v2 dV Tt2=yes Nn10,n11 | 0 | 1 |
171171

172172

173173
Scenario Outline: change valid geom to invalid geom
174174
Given the OSM data
175175
"""
176+
w10 v1 dV Tt1=yes,t2=yes,tboth=yes Nn10,n11
176177
w11 v1 dV Tt1=yes Nn12,n13
177178
w12 v1 dV Tt2=yes Nn14,n15
178179
w13 v1 dV Ttboth=yes Nn16,n17
179180
w14 v1 dV Ttboth=yes Nn18,n19
180-
w10 v1 dV Tt1=yes,t2=yes,tboth=yes Nn10,n11
181181
r30 v1 dV Tt=ag Mw10@mark,w11@,w12@mark,w13@,w14@mark
182182
"""
183183
When running osm2pgsql flex with parameters
@@ -223,11 +223,11 @@ Feature: Changing ways in a flex database
223223
Scenario: change invalid geom to valid geom
224224
Given the OSM data
225225
"""
226+
w10 v1 dV Tt1=yes,t2=yes,tboth=yes Nn10
226227
w11 v1 dV Tt1=yes Nn12,n13
227228
w12 v1 dV Tt2=yes Nn14,n15
228229
w13 v1 dV Ttboth=yes Nn16,n17
229230
w14 v1 dV Ttboth=yes Nn18,n19
230-
w10 v1 dV Tt1=yes,t2=yes,tboth=yes Nn10
231231
r30 v1 dV Tt=ag Mw10@mark,w11@,w12@mark,w13@,w14@mark
232232
"""
233233
When running osm2pgsql flex with parameters

0 commit comments

Comments
 (0)