diff --git a/src/output-flex.cpp b/src/output-flex.cpp index 7b6452294..daccd60fd 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -1075,12 +1075,12 @@ void output_flex_t::after_ways() void output_flex_t::stop() { for (auto &table : m_table_connections) { - auto *db_connection = &m_db_connections.at(table.table().num()); - table.task_set(thread_pool().submit([&, db_connection]() { - table.stop(*db_connection, + table.task_set(thread_pool().submit([&]() { + pg_conn_t const db_connection{get_options()->connection_params, + "out.flex.stop"}; + table.stop(db_connection, get_options()->slim && !get_options()->droptemp, get_options()->append); - db_connection->close(); })); } @@ -1185,8 +1185,7 @@ void output_flex_t::delete_from_tables(osmium::item_type type, osmid_t osm_id) { for (auto &table : m_table_connections) { if (table.table().matches_type(type) && table.table().has_id_column()) { - delete_from_table(&table, m_db_connections.at(table.table().num()), - type, osm_id); + delete_from_table(&table, m_db_connection, type, osm_id); } } } @@ -1230,12 +1229,8 @@ void output_flex_t::relation_modify(osmium::Relation const &rel) void output_flex_t::start() { - assert(m_db_connections.empty()); - for (auto &table : m_table_connections) { - m_db_connections.emplace_back(get_options()->connection_params, - "out.flex.table"); - table.start(m_db_connections.back(), get_options()->append); + table.start(m_db_connection, get_options()->append); } } @@ -1263,19 +1258,16 @@ output_flex_t::output_flex_t(output_flex_t const *other, std::shared_ptr copy_thread) : output_t(other, std::move(mid)), m_tables(other->m_tables), m_expire_outputs(other->m_expire_outputs), + m_db_connection(get_options()->connection_params, "out.flex.thread"), m_stage2_way_ids(other->m_stage2_way_ids), m_copy_thread(std::move(copy_thread)), m_lua_state(other->m_lua_state), m_process_node(other->m_process_node), m_process_way(other->m_process_way), m_process_relation(other->m_process_relation), m_select_relation_members(other->m_select_relation_members) { - assert(m_db_connections.empty()); - for (auto &table : *m_tables) { auto &tc = m_table_connections.emplace_back(&table, m_copy_thread); - m_db_connections.emplace_back(get_options()->connection_params, - "out.flex.table"); - tc.prepare(m_db_connections.back()); + tc.prepare(m_db_connection); } for (auto &expire_output : *m_expire_outputs) { @@ -1295,6 +1287,7 @@ output_flex_t::output_flex_t(std::shared_ptr const &mid, std::shared_ptr thread_pool, options_t const &options) : output_t(mid, std::move(thread_pool), options), + m_db_connection(get_options()->connection_params, "out.flex.main"), m_copy_thread(std::make_shared(options.connection_params)) { init_lua(options.style); @@ -1521,10 +1514,8 @@ void output_flex_t::reprocess_marked() for (auto &table : m_table_connections) { if (table.table().matches_type(osmium::item_type::way) && table.table().has_id_column()) { - auto const &db_connection = - m_db_connections.at(table.table().num()); - table.analyze(db_connection); - table.create_id_index(db_connection); + table.analyze(m_db_connection); + table.create_id_index(m_db_connection); } } diff --git a/src/output-flex.hpp b/src/output-flex.hpp index ae812502c..b64d15e13 100644 --- a/src/output-flex.hpp +++ b/src/output-flex.hpp @@ -290,8 +290,8 @@ class output_flex_t : public output_t std::vector m_table_connections; - /// The connections to the database server for each table. - std::vector m_db_connections; + /// The connection to the database server. + pg_conn_t m_db_connection; // This is shared between all clones of the output and must only be // accessed while protected using the lua_mutex.