Avoid copying options inside output_t and access them through getter
The options were copied into output_t::m_options, that's not good because they are huge. Also this cleans up access to those options from derived classes only through the get_options() member function.HEAD
parent
51565f490a
commit
a0c4578802
|
@ -1449,13 +1449,15 @@ void output_flex_t::stop()
|
|||
{
|
||||
for (auto &table : m_table_connections) {
|
||||
table.task_set(thread_pool().submit([&]() {
|
||||
table.stop(m_options.slim && !m_options.droptemp, m_options.append);
|
||||
table.stop(get_options()->slim && !get_options()->droptemp,
|
||||
get_options()->append);
|
||||
}));
|
||||
}
|
||||
|
||||
if (m_options.expire_tiles_zoom_min > 0) {
|
||||
m_expire.output_and_destroy(m_options.expire_tiles_filename.c_str(),
|
||||
m_options.expire_tiles_zoom_min);
|
||||
if (get_options()->expire_tiles_zoom_min > 0) {
|
||||
m_expire.output_and_destroy(
|
||||
get_options()->expire_tiles_filename.c_str(),
|
||||
get_options()->expire_tiles_zoom_min);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1572,7 +1574,7 @@ void output_flex_t::relation_modify(osmium::Relation const &rel)
|
|||
void output_flex_t::init_clone()
|
||||
{
|
||||
for (auto &table : m_table_connections) {
|
||||
table.connect(m_options.database_options.conninfo());
|
||||
table.connect(get_options()->database_options.conninfo());
|
||||
table.prepare();
|
||||
}
|
||||
}
|
||||
|
@ -1580,8 +1582,8 @@ void output_flex_t::init_clone()
|
|||
void output_flex_t::start()
|
||||
{
|
||||
for (auto &table : m_table_connections) {
|
||||
table.connect(m_options.database_options.conninfo());
|
||||
table.start(m_options.append);
|
||||
table.connect(get_options()->database_options.conninfo());
|
||||
table.start(get_options()->append);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1618,7 +1620,7 @@ output_flex_t::output_flex_t(
|
|||
assert(copy_thread);
|
||||
|
||||
if (!is_clone) {
|
||||
init_lua(m_options.style);
|
||||
init_lua(get_options()->style);
|
||||
|
||||
// If the osm2pgsql.select_relation_members() Lua function is defined
|
||||
// it means we need two-stage processing which in turn means we need
|
||||
|
@ -1656,7 +1658,7 @@ void output_flex_t::init_lua(std::string const &filename)
|
|||
|
||||
luaX_add_table_str(lua_state(), "version", get_osm2pgsql_short_version());
|
||||
luaX_add_table_str(lua_state(), "mode",
|
||||
m_options.append ? "append" : "create");
|
||||
get_options()->append ? "append" : "create");
|
||||
luaX_add_table_int(lua_state(), "stage", 1);
|
||||
|
||||
std::string dir_path =
|
||||
|
@ -1755,7 +1757,7 @@ void output_flex_t::reprocess_marked()
|
|||
|
||||
log_info("Reprocess marked ways (stage 2)...");
|
||||
|
||||
if (!m_options.append) {
|
||||
if (!get_options()->append) {
|
||||
util::timer_t timer;
|
||||
|
||||
for (auto &table : m_table_connections) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
void output_gazetteer_t::delete_unused_classes(char osm_type, osmid_t osm_id)
|
||||
{
|
||||
if (m_options.append) {
|
||||
if (get_options()->append) {
|
||||
m_copy.prepare();
|
||||
|
||||
assert(m_style.has_data());
|
||||
|
@ -35,7 +35,7 @@ void output_gazetteer_t::delete_unused_classes(char osm_type, osmid_t osm_id)
|
|||
|
||||
void output_gazetteer_t::delete_unused_full(char osm_type, osmid_t osm_id)
|
||||
{
|
||||
if (m_options.append) {
|
||||
if (get_options()->append) {
|
||||
m_copy.prepare();
|
||||
m_copy.delete_object(osm_type, osm_id);
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ void output_gazetteer_t::delete_unused_full(char osm_type, osmid_t osm_id)
|
|||
void output_gazetteer_t::start()
|
||||
{
|
||||
/* (Re)create the table unless we are appending */
|
||||
if (!m_options.append) {
|
||||
int const srid = m_options.projection->target_srs();
|
||||
if (!get_options()->append) {
|
||||
int const srid = get_options()->projection->target_srs();
|
||||
|
||||
pg_conn_t conn{m_options.database_options.conninfo()};
|
||||
pg_conn_t conn{get_options()->database_options.conninfo()};
|
||||
|
||||
/* Drop any existing table */
|
||||
conn.exec("DROP TABLE IF EXISTS place CASCADE");
|
||||
|
@ -65,14 +65,14 @@ void output_gazetteer_t::start()
|
|||
" address hstore,"
|
||||
" extratags hstore," +
|
||||
" geometry Geometry(Geometry,{}) NOT NULL"_format(srid) + ")" +
|
||||
tablespace_clause(m_options.tblsmain_data);
|
||||
tablespace_clause(get_options()->tblsmain_data);
|
||||
|
||||
conn.exec(sql);
|
||||
|
||||
std::string const index_sql =
|
||||
"CREATE INDEX place_id_idx ON place"
|
||||
" USING BTREE (osm_type, osm_id)" +
|
||||
tablespace_clause(m_options.tblsmain_index);
|
||||
tablespace_clause(get_options()->tblsmain_index);
|
||||
conn.exec(index_sql);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ class output_gazetteer_t : public output_t
|
|||
output_gazetteer_t(output_gazetteer_t const *other,
|
||||
std::shared_ptr<middle_query_t> const &cloned_mid,
|
||||
std::shared_ptr<db_copy_thread_t> const ©_thread)
|
||||
: output_t(cloned_mid, other->m_thread_pool, other->m_options),
|
||||
m_copy(copy_thread), m_proj(other->m_options.projection),
|
||||
: output_t(cloned_mid, other->m_thread_pool, *other->get_options()),
|
||||
m_copy(copy_thread), m_proj(other->get_options()->projection),
|
||||
m_osmium_buffer(PLACE_BUFFER_SIZE, osmium::memory::Buffer::auto_grow::yes)
|
||||
{}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ std::shared_ptr<output_t>
|
|||
output_null_t::clone(std::shared_ptr<middle_query_t> const &mid,
|
||||
std::shared_ptr<db_copy_thread_t> const &) const
|
||||
{
|
||||
return std::make_shared<output_null_t>(mid, m_thread_pool, m_options);
|
||||
return std::make_shared<output_null_t>(mid, m_thread_pool, *get_options());
|
||||
}
|
||||
|
||||
output_null_t::output_null_t(std::shared_ptr<middle_query_t> const &mid,
|
||||
|
|
|
@ -69,8 +69,8 @@ void output_pgsql_t::pgsql_out_way(osmium::Way const &way, taglist_t *tags,
|
|||
if (!wkb.empty()) {
|
||||
m_expire.from_geometry(projected_geom, way.id());
|
||||
if (m_enable_way_area) {
|
||||
double const area = calculate_area(m_options.reproject_area,
|
||||
geom, projected_geom);
|
||||
double const area = calculate_area(
|
||||
get_options()->reproject_area, geom, projected_geom);
|
||||
util::double_to_buffer tmp{area};
|
||||
tags->set("way_area", tmp.c_str());
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void output_pgsql_t::pgsql_out_way(osmium::Way const &way, taglist_t *tags,
|
|||
}
|
||||
} else {
|
||||
double const split_at =
|
||||
m_options.projection->target_latlon() ? 1 : 100 * 1000;
|
||||
get_options()->projection->target_latlon() ? 1 : 100 * 1000;
|
||||
auto const geoms = geom::split_multi(geom::segmentize(
|
||||
geom::transform(geom::create_linestring(way), *m_proj), split_at));
|
||||
for (auto const &sgeom : geoms) {
|
||||
|
@ -139,14 +139,16 @@ void output_pgsql_t::stop()
|
|||
{
|
||||
for (auto &t : m_tables) {
|
||||
t->task_set(thread_pool().submit([&]() {
|
||||
t->stop(m_options.slim && !m_options.droptemp,
|
||||
m_options.enable_hstore_index, m_options.tblsmain_index);
|
||||
t->stop(get_options()->slim && !get_options()->droptemp,
|
||||
get_options()->enable_hstore_index,
|
||||
get_options()->tblsmain_index);
|
||||
}));
|
||||
}
|
||||
|
||||
if (m_options.expire_tiles_zoom_min > 0) {
|
||||
m_expire.output_and_destroy(m_options.expire_tiles_filename.c_str(),
|
||||
m_options.expire_tiles_zoom_min);
|
||||
if (get_options()->expire_tiles_zoom_min > 0) {
|
||||
m_expire.output_and_destroy(
|
||||
get_options()->expire_tiles_filename.c_str(),
|
||||
get_options()->expire_tiles_zoom_min);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,7 +241,7 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
|
|||
taglist_t outtags;
|
||||
|
||||
rolelist_t xrole;
|
||||
if (!m_options.tag_transform_script.empty()) {
|
||||
if (!get_options()->tag_transform_script.empty()) {
|
||||
xrole = get_rolelist(rel, m_buffer);
|
||||
}
|
||||
|
||||
|
@ -260,7 +262,7 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
|
|||
// for boundaries the way_area tag may be added.
|
||||
if (!make_polygon) {
|
||||
double const split_at =
|
||||
m_options.projection->target_latlon() ? 1 : 100 * 1000;
|
||||
get_options()->projection->target_latlon() ? 1 : 100 * 1000;
|
||||
auto geom = geom::line_merge(geom::create_multilinestring(m_buffer));
|
||||
auto projected_geom = geom::transform(geom, *m_proj);
|
||||
if (!projected_geom.is_null() && split_at > 0.0) {
|
||||
|
@ -279,15 +281,16 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
|
|||
|
||||
// multipolygons and boundaries
|
||||
if (make_boundary || make_polygon) {
|
||||
auto const geoms = geom::split_multi(
|
||||
geom::create_multipolygon(rel, m_buffer), !m_options.enable_multi);
|
||||
auto const geoms =
|
||||
geom::split_multi(geom::create_multipolygon(rel, m_buffer),
|
||||
!get_options()->enable_multi);
|
||||
for (auto const &sgeom : geoms) {
|
||||
auto const projected_geom = geom::transform(sgeom, *m_proj);
|
||||
m_expire.from_geometry(projected_geom, -rel.id());
|
||||
auto const wkb = geom_to_ewkb(projected_geom);
|
||||
if (m_enable_way_area) {
|
||||
double const area = calculate_area(m_options.reproject_area,
|
||||
sgeom, projected_geom);
|
||||
double const area = calculate_area(
|
||||
get_options()->reproject_area, sgeom, projected_geom);
|
||||
util::double_to_buffer tmp{area};
|
||||
outtags.set("way_area", tmp.c_str());
|
||||
}
|
||||
|
@ -329,11 +332,11 @@ void output_pgsql_t::node_delete(osmid_t osm_id)
|
|||
void output_pgsql_t::pgsql_delete_way_from_output(osmid_t osm_id)
|
||||
{
|
||||
/* Optimisation: we only need this is slim mode */
|
||||
if (!m_options.slim) {
|
||||
if (!get_options()->slim) {
|
||||
return;
|
||||
}
|
||||
/* in droptemp mode we don't have indices and this takes ages. */
|
||||
if (m_options.droptemp) {
|
||||
if (get_options()->droptemp) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -395,8 +398,8 @@ void output_pgsql_t::start()
|
|||
{
|
||||
for (auto &t : m_tables) {
|
||||
//setup the table in postgres
|
||||
t->start(m_options.database_options.conninfo(),
|
||||
m_options.tblsmain_data);
|
||||
t->start(get_options()->database_options.conninfo(),
|
||||
get_options()->tblsmain_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,9 +425,9 @@ output_pgsql_t::output_pgsql_t(
|
|||
|
||||
export_list exlist;
|
||||
|
||||
m_enable_way_area = read_style_file(m_options.style, &exlist);
|
||||
m_enable_way_area = read_style_file(get_options()->style, &exlist);
|
||||
|
||||
m_tagtransform = tagtransform_t::make_tagtransform(&m_options, exlist);
|
||||
m_tagtransform = tagtransform_t::make_tagtransform(get_options(), exlist);
|
||||
|
||||
//for each table
|
||||
for (size_t i = 0; i < t_MAX; ++i) {
|
||||
|
@ -434,7 +437,7 @@ output_pgsql_t::output_pgsql_t(
|
|||
(i == t_point) ? osmium::item_type::node : osmium::item_type::way);
|
||||
|
||||
//figure out what name we are using for this and what type
|
||||
std::string name = m_options.prefix;
|
||||
std::string name = get_options()->prefix;
|
||||
std::string type;
|
||||
switch (i) {
|
||||
case t_point:
|
||||
|
@ -459,20 +462,22 @@ output_pgsql_t::output_pgsql_t(
|
|||
}
|
||||
|
||||
m_tables[i] = std::make_unique<table_t>(
|
||||
name, type, columns, m_options.hstore_columns,
|
||||
m_options.projection->target_srs(), m_options.append,
|
||||
m_options.hstore_mode, copy_thread, m_options.output_dbschema);
|
||||
name, type, columns, get_options()->hstore_columns,
|
||||
get_options()->projection->target_srs(), get_options()->append,
|
||||
get_options()->hstore_mode, copy_thread,
|
||||
get_options()->output_dbschema);
|
||||
}
|
||||
}
|
||||
|
||||
output_pgsql_t::output_pgsql_t(
|
||||
output_pgsql_t const *other, std::shared_ptr<middle_query_t> const &mid,
|
||||
std::shared_ptr<db_copy_thread_t> const ©_thread)
|
||||
: output_t(mid, other->m_thread_pool, other->m_options),
|
||||
: output_t(mid, other->m_thread_pool, *other->get_options()),
|
||||
m_tagtransform(other->m_tagtransform->clone()),
|
||||
m_enable_way_area(other->m_enable_way_area), m_proj(m_options.projection),
|
||||
m_expire(m_options.expire_tiles_zoom, m_options.expire_tiles_max_bbox,
|
||||
m_options.projection),
|
||||
m_enable_way_area(other->m_enable_way_area),
|
||||
m_proj(get_options()->projection),
|
||||
m_expire(get_options()->expire_tiles_zoom,
|
||||
get_options()->expire_tiles_max_bbox, get_options()->projection),
|
||||
m_buffer(1024, osmium::memory::Buffer::auto_grow::yes),
|
||||
m_rels_buffer(1024, osmium::memory::Buffer::auto_grow::yes)
|
||||
{
|
||||
|
|
|
@ -66,8 +66,9 @@ output_t::create_output(std::shared_ptr<middle_query_t> const &mid,
|
|||
output_t::output_t(std::shared_ptr<middle_query_t> mid,
|
||||
std::shared_ptr<thread_pool_t> thread_pool,
|
||||
options_t const &options)
|
||||
: m_mid(std::move(mid)), m_thread_pool(std::move(thread_pool)),
|
||||
m_options(options)
|
||||
: m_mid(std::move(mid)), m_options(&options),
|
||||
m_thread_pool(std::move(thread_pool))
|
||||
|
||||
{}
|
||||
|
||||
output_t::~output_t() = default;
|
||||
|
@ -77,6 +78,4 @@ void output_t::free_middle_references()
|
|||
m_mid.reset();
|
||||
}
|
||||
|
||||
options_t const *output_t::get_options() const { return &m_options; }
|
||||
|
||||
void output_t::merge_expire_trees(output_t *) {}
|
||||
|
|
|
@ -86,8 +86,6 @@ public:
|
|||
virtual void way_delete(osmid_t id) = 0;
|
||||
virtual void relation_delete(osmid_t id) = 0;
|
||||
|
||||
const options_t *get_options() const;
|
||||
|
||||
virtual void merge_expire_trees(output_t *other);
|
||||
|
||||
struct output_requirements const &get_requirements() const noexcept
|
||||
|
@ -97,6 +95,7 @@ public:
|
|||
|
||||
private:
|
||||
std::shared_ptr<middle_query_t> m_mid;
|
||||
options_t const *m_options;
|
||||
|
||||
protected:
|
||||
thread_pool_t &thread_pool() const noexcept
|
||||
|
@ -111,8 +110,9 @@ protected:
|
|||
return *m_mid;
|
||||
}
|
||||
|
||||
const options_t *get_options() const noexcept { return m_options; };
|
||||
|
||||
std::shared_ptr<thread_pool_t> m_thread_pool;
|
||||
const options_t m_options;
|
||||
output_requirements m_output_requirements{};
|
||||
};
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ struct counting_output_t : public output_null_t
|
|||
clone(std::shared_ptr<middle_query_t> const &,
|
||||
std::shared_ptr<db_copy_thread_t> const &) const override
|
||||
{
|
||||
return std::make_shared<counting_output_t>(m_options);
|
||||
return std::make_shared<counting_output_t>(*get_options());
|
||||
}
|
||||
|
||||
void node_add(osmium::Node const &n) override
|
||||
|
|
Loading…
Reference in New Issue