Skip to content

Commit ae3f242

Browse files
committed
Make expire_tiles::from_result a free function
The from_result function doesn't know anything about the insides of the expire_tiles class and doesn't need to know. And remove some code duplication in the pgsql output.
1 parent b7e1712 commit ae3f242

5 files changed

Lines changed: 52 additions & 42 deletions

File tree

src/expire-tiles.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,6 @@ int expire_tiles::from_bbox(geom::box_t const &box)
230230
return 0;
231231
}
232232

233-
int expire_tiles::from_result(pg_result_t const &result)
234-
{
235-
if (!enabled()) {
236-
return -1;
237-
}
238-
239-
auto const num_tuples = result.num_tuples();
240-
for (int i = 0; i < num_tuples; ++i) {
241-
char const *const wkb = result.get_value(i, 0);
242-
from_geometry(ewkb_to_geom(decode_hex(wkb)));
243-
}
244-
245-
return num_tuples;
246-
}
247-
248233
quadkey_list_t expire_tiles::get_tiles()
249234
{
250235
quadkey_list_t tiles;
@@ -293,3 +278,18 @@ std::size_t output_tiles_to_file(quadkey_list_t const &tiles_maxzoom,
293278

294279
return count;
295280
}
281+
282+
int expire_from_result(expire_tiles *expire, pg_result_t const &result)
283+
{
284+
if (!expire->enabled()) {
285+
return -1;
286+
}
287+
288+
auto const num_tuples = result.num_tuples();
289+
for (int i = 0; i < num_tuples; ++i) {
290+
char const *const wkb = result.get_value(i, 0);
291+
expire->from_geometry(ewkb_to_geom(decode_hex(wkb)));
292+
}
293+
294+
return num_tuples;
295+
}

src/expire-tiles.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ class expire_tiles
3636

3737
int from_bbox(geom::box_t const &box);
3838

39-
/**
40-
* Expire tiles based on an osm id.
41-
*
42-
* \param result Result of a database query into some table returning the
43-
* geometries. (This is usually done using the "get_wkb"
44-
* prepared statement.)
45-
* \return The number of tuples in the result or -1 if expire is disabled.
46-
*/
47-
int from_result(pg_result_t const &result);
48-
4939
/**
5040
* Get tiles as a vector of quadkeys and remove them from the expire_tiles
5141
* object.
@@ -88,7 +78,19 @@ class expire_tiles
8878
double m_max_bbox;
8979
uint32_t m_maxzoom;
9080
int m_map_width;
91-
};
81+
82+
}; // class expire_tiles
83+
84+
/**
85+
* Expire tiles based on an osm id.
86+
*
87+
* \param expire Where to mark expired tiles.
88+
* \param result Result of a database query into some table returning the
89+
* geometries. (This is usually done using the "get_wkb"
90+
* prepared statement.)
91+
* \return The number of tuples in the result or -1 if expire is disabled.
92+
*/
93+
int expire_from_result(expire_tiles *expire, pg_result_t const &result);
9294

9395
/**
9496
* Iterate over tiles and call output function for each tile on all requested

src/output-flex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ void output_flex_t::delete_from_table(table_connection_t *table_connection,
19151915
return;
19161916
}
19171917

1918-
m_expire.from_result(result);
1918+
expire_from_result(&m_expire, result);
19191919
}
19201920

19211921
table_connection->delete_rows_with(type, id);

src/output-pgsql.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,24 @@ void output_pgsql_t::relation_add(osmium::Relation const &rel)
325325
* contain the change for that also. */
326326
void output_pgsql_t::node_delete(osmid_t osm_id)
327327
{
328-
if (m_expire.from_result(m_tables[t_point]->get_wkb(osm_id)) != 0) {
328+
auto const results = m_tables[t_point]->get_wkb(osm_id);
329+
if (expire_from_result(&m_expire, results) != 0) {
329330
m_tables[t_point]->delete_row(osm_id);
330331
}
331332
}
332333

334+
void output_pgsql_t::delete_from_output_and_expire(osmid_t id)
335+
{
336+
m_tables[t_roads]->delete_row(id);
337+
338+
for (auto table : {t_line, t_poly}) {
339+
auto const results = m_tables[table]->get_wkb(id);
340+
if (expire_from_result(&m_expire, results) != 0) {
341+
m_tables[table]->delete_row(id);
342+
}
343+
}
344+
}
345+
333346
/* Seperated out because we use it elsewhere */
334347
void output_pgsql_t::pgsql_delete_way_from_output(osmid_t osm_id)
335348
{
@@ -342,13 +355,7 @@ void output_pgsql_t::pgsql_delete_way_from_output(osmid_t osm_id)
342355
return;
343356
}
344357

345-
m_tables[t_roads]->delete_row(osm_id);
346-
if (m_expire.from_result(m_tables[t_line]->get_wkb(osm_id)) != 0) {
347-
m_tables[t_line]->delete_row(osm_id);
348-
}
349-
if (m_expire.from_result(m_tables[t_poly]->get_wkb(osm_id)) != 0) {
350-
m_tables[t_poly]->delete_row(osm_id);
351-
}
358+
delete_from_output_and_expire(osm_id);
352359
}
353360

354361
void output_pgsql_t::way_delete(osmid_t osm_id)
@@ -359,13 +366,7 @@ void output_pgsql_t::way_delete(osmid_t osm_id)
359366
/* Relations are identified by using negative IDs */
360367
void output_pgsql_t::pgsql_delete_relation_from_output(osmid_t osm_id)
361368
{
362-
m_tables[t_roads]->delete_row(-osm_id);
363-
if (m_expire.from_result(m_tables[t_line]->get_wkb(-osm_id)) != 0) {
364-
m_tables[t_line]->delete_row(-osm_id);
365-
}
366-
if (m_expire.from_result(m_tables[t_poly]->get_wkb(-osm_id)) != 0) {
367-
m_tables[t_poly]->delete_row(-osm_id);
368-
}
369+
delete_from_output_and_expire(-osm_id);
369370
}
370371

371372
void output_pgsql_t::relation_delete(osmid_t osm_id)

src/output-pgsql.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class output_pgsql_t : public output_t
7979
void pgsql_out_way(osmium::Way const &way, taglist_t *tags, bool polygon,
8080
bool roads);
8181
void pgsql_process_relation(osmium::Relation const &rel);
82+
83+
/**
84+
* Delete all objects with specified id from all output tables and mark
85+
* their geometries for expire.
86+
*/
87+
void delete_from_output_and_expire(osmid_t id);
88+
8289
void pgsql_delete_way_from_output(osmid_t osm_id);
8390
void pgsql_delete_relation_from_output(osmid_t osm_id);
8491

0 commit comments

Comments
 (0)