Skip to content

Commit ceedd7e

Browse files
authored
Merge pull request #1479 from joto/remove-wkb-reader
Simplify code around expiry
2 parents 7773457 + 663e913 commit ceedd7e

File tree

5 files changed

+22
-67
lines changed

5 files changed

+22
-67
lines changed

src/expire-tiles.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -377,37 +377,6 @@ void expire_tiles::from_wkb_polygon(ewkb::parser_t *wkb, osmid_t osm_id)
377377
}
378378
}
379379

380-
/*
381-
* Expire tiles based on an osm element.
382-
* What type of element (node, line, polygon) osm_id refers to depends on
383-
* sql_conn. Each type of table has its own sql_conn and the prepared statement
384-
* get_wkb refers to the appropriate table.
385-
*
386-
* The function returns -1 if expiry is not enabled. Otherwise it returns the number
387-
* of elements that refer to the osm_id.
388-
389-
*/
390-
int expire_tiles::from_db(table_t *table, osmid_t osm_id)
391-
{
392-
//bail if we dont care about expiry
393-
if (maxzoom == 0) {
394-
return -1;
395-
}
396-
397-
//grab the geom for this id
398-
auto wkbs = table->get_wkb_reader(osm_id);
399-
400-
//dirty the stuff
401-
char const *wkb = nullptr;
402-
while ((wkb = wkbs.get_next())) {
403-
auto const binwkb = ewkb::parser_t::wkb_from_hex(wkb);
404-
from_wkb(binwkb, osm_id);
405-
}
406-
407-
//return how many rows were affected
408-
return wkbs.get_count();
409-
}
410-
411380
int expire_tiles::from_result(pg_result_t const &result, osmid_t osm_id)
412381
{
413382
//bail if we dont care about expiry

src/expire-tiles.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ struct expire_tiles
6565
int from_bbox(double min_lon, double min_lat, double max_lon,
6666
double max_lat);
6767
void from_wkb(std::string const &wkb, osmid_t osm_id);
68-
int from_db(table_t *table, osmid_t osm_id);
68+
69+
/**
70+
* Expire tiles based on an osm id.
71+
*
72+
* \param result Result of a database query into some table returning the
73+
* geometries. (This is usally done using the "get_wkb"
74+
* prepared statement.)
75+
* \param osm_id The OSM id to look for.
76+
* \return The number of elements that refer to the osm_id or -1 if
77+
* expire is disabled.
78+
*/
6979
int from_result(pg_result_t const &result, osmid_t osm_id);
7080

7181
/**

src/output-pgsql.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void output_pgsql_t::relation_add(osmium::Relation const &rel)
294294
* contain the change for that also. */
295295
void output_pgsql_t::node_delete(osmid_t osm_id)
296296
{
297-
if (m_expire.from_db(m_tables[t_point].get(), osm_id) != 0) {
297+
if (m_expire.from_result(m_tables[t_point]->get_wkb(osm_id), osm_id) != 0) {
298298
m_tables[t_point]->delete_row(osm_id);
299299
}
300300
}
@@ -312,10 +312,10 @@ void output_pgsql_t::pgsql_delete_way_from_output(osmid_t osm_id)
312312
}
313313

314314
m_tables[t_roads]->delete_row(osm_id);
315-
if (m_expire.from_db(m_tables[t_line].get(), osm_id) != 0) {
315+
if (m_expire.from_result(m_tables[t_line]->get_wkb(osm_id), osm_id) != 0) {
316316
m_tables[t_line]->delete_row(osm_id);
317317
}
318-
if (m_expire.from_db(m_tables[t_poly].get(), osm_id) != 0) {
318+
if (m_expire.from_result(m_tables[t_poly]->get_wkb(osm_id), osm_id) != 0) {
319319
m_tables[t_poly]->delete_row(osm_id);
320320
}
321321
}
@@ -329,10 +329,12 @@ void output_pgsql_t::way_delete(osmid_t osm_id)
329329
void output_pgsql_t::pgsql_delete_relation_from_output(osmid_t osm_id)
330330
{
331331
m_tables[t_roads]->delete_row(-osm_id);
332-
if (m_expire.from_db(m_tables[t_line].get(), -osm_id) != 0) {
332+
if (m_expire.from_result(m_tables[t_line]->get_wkb(-osm_id), -osm_id) !=
333+
0) {
333334
m_tables[t_line]->delete_row(-osm_id);
334335
}
335-
if (m_expire.from_db(m_tables[t_poly].get(), -osm_id) != 0) {
336+
if (m_expire.from_result(m_tables[t_poly]->get_wkb(-osm_id), -osm_id) !=
337+
0) {
336338
m_tables[t_poly]->delete_row(-osm_id);
337339
}
338340
}

src/table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ void table_t::escape_type(std::string const &value, ColumnType flags)
442442
}
443443
}
444444

445-
table_t::wkb_reader table_t::get_wkb_reader(osmid_t id)
445+
pg_result_t table_t::get_wkb(osmid_t id)
446446
{
447-
auto res = m_sql_conn->exec_prepared("get_wkb", id);
448-
return wkb_reader{std::move(res)};
447+
return m_sql_conn->exec_prepared("get_wkb", id);
449448
}
449+

src/table.hpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,7 @@ class table_t
4343
void write_row(osmid_t id, taglist_t const &tags, std::string const &geom);
4444
void delete_row(osmid_t id);
4545

46-
// interface for retrieving well known binary geometry from the table
47-
class wkb_reader
48-
{
49-
friend table_t;
50-
51-
public:
52-
char const *get_next()
53-
{
54-
if (m_current < m_count) {
55-
return m_result.get_value(m_current++, 0);
56-
}
57-
return nullptr;
58-
}
59-
60-
int get_count() const noexcept { return m_count; }
61-
62-
private:
63-
explicit wkb_reader(pg_result_t &&result)
64-
: m_result(std::move(result)), m_count(m_result.num_tuples()),
65-
m_current(0)
66-
{}
67-
68-
pg_result_t m_result;
69-
int m_count;
70-
int m_current;
71-
};
72-
wkb_reader get_wkb_reader(osmid_t id);
46+
pg_result_t get_wkb(osmid_t id);
7347

7448
protected:
7549
void connect();

0 commit comments

Comments
 (0)