Skip to content

Commit e6c0986

Browse files
committed
Add max_tiles_per_run setting for tile generalizers
Limits the number of tiles for which the generalizer is run. Used when generalization is too expensive to always run for all expired tiles. There is a good chance that later changes in the data affect the same tile again, so in the long run this saves effort. Tiles are generalized oldest first when this is used. Don't set max_tiles_per_run or set to 0 to run generalization for all tiles in the expire table for that zoom level.
1 parent 47442e5 commit e6c0986

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/gen/osm2pgsql-gen.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,30 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection,
171171
}
172172

173173
void get_tiles_from_table(pg_conn_t const &connection, std::string const &table,
174-
uint32_t zoom,
174+
uint32_t zoom, int64_t max_tiles_per_run,
175175
std::vector<std::pair<uint32_t, uint32_t>> *tiles)
176176
{
177-
auto const result = connection.exec(
178-
R"(DELETE FROM "{}" WHERE zoom = {} RETURNING x, y)", table, zoom);
177+
std::string query;
178+
if (max_tiles_per_run == 0) {
179+
query = fmt::format(
180+
R"(DELETE FROM "{}" WHERE zoom = {} RETURNING x, y)", table, zoom);
181+
} else {
182+
query = fmt::format(R"(
183+
WITH to_delete AS (
184+
SELECT t.ctid FROM "{0}" AS t
185+
WHERE zoom = {1}
186+
ORDER BY first
187+
FOR UPDATE
188+
LIMIT {2}
189+
)
190+
DELETE FROM "{0}" AS et
191+
USING to_delete AS del
192+
WHERE et.ctid = del.ctid
193+
RETURNING x, y;)",
194+
table, zoom, max_tiles_per_run);
195+
}
196+
197+
auto const result = connection.exec(query);
179198

180199
tiles->reserve(result.num_tuples());
181200

@@ -473,9 +492,12 @@ class genproc_t
473492
std::vector<std::pair<uint32_t, uint32_t>> tile_list;
474493
if (m_append) {
475494
auto const table = params.get_string("expire_list");
495+
auto const max_tiles_per_run =
496+
params.get_int64("max_tiles_per_run", 0);
476497
log_debug("Running generalizer for expire list from table '{}'...",
477498
table);
478-
get_tiles_from_table(db_connection, table, zoom, &tile_list);
499+
get_tiles_from_table(db_connection, table, zoom, max_tiles_per_run,
500+
&tile_list);
479501
} else {
480502
auto const extent =
481503
get_extent_from_db(db_connection, m_dbschema, params, zoom);

0 commit comments

Comments
 (0)