@@ -1075,12 +1075,12 @@ void output_flex_t::after_ways()
10751075void output_flex_t::stop ()
10761076{
10771077 for (auto &table : m_table_connections) {
1078- auto *db_connection = &m_db_connections.at (table.table ().num ());
1079- table.task_set (thread_pool ().submit ([&, db_connection]() {
1080- table.stop (*db_connection,
1078+ table.task_set (thread_pool ().submit ([&]() {
1079+ pg_conn_t const db_connection{get_options ()->connection_params ,
1080+ " out.flex.stop" };
1081+ table.stop (db_connection,
10811082 get_options ()->slim && !get_options ()->droptemp ,
10821083 get_options ()->append );
1083- db_connection->close ();
10841084 }));
10851085 }
10861086
@@ -1185,8 +1185,7 @@ void output_flex_t::delete_from_tables(osmium::item_type type, osmid_t osm_id)
11851185{
11861186 for (auto &table : m_table_connections) {
11871187 if (table.table ().matches_type (type) && table.table ().has_id_column ()) {
1188- delete_from_table (&table, m_db_connections.at (table.table ().num ()),
1189- type, osm_id);
1188+ delete_from_table (&table, m_db_connection, type, osm_id);
11901189 }
11911190 }
11921191}
@@ -1230,12 +1229,8 @@ void output_flex_t::relation_modify(osmium::Relation const &rel)
12301229
12311230void output_flex_t::start ()
12321231{
1233- assert (m_db_connections.empty ());
1234-
12351232 for (auto &table : m_table_connections) {
1236- m_db_connections.emplace_back (get_options ()->connection_params ,
1237- " out.flex.table" );
1238- table.start (m_db_connections.back (), get_options ()->append );
1233+ table.start (m_db_connection, get_options ()->append );
12391234 }
12401235}
12411236
@@ -1263,19 +1258,16 @@ output_flex_t::output_flex_t(output_flex_t const *other,
12631258 std::shared_ptr<db_copy_thread_t > copy_thread)
12641259: output_t (other, std::move(mid)), m_tables(other->m_tables),
12651260 m_expire_outputs (other->m_expire_outputs),
1261+ m_db_connection(get_options()->connection_params, "out.flex.thread"),
12661262 m_stage2_way_ids(other->m_stage2_way_ids),
12671263 m_copy_thread(std::move(copy_thread)), m_lua_state(other->m_lua_state),
12681264 m_process_node(other->m_process_node), m_process_way(other->m_process_way),
12691265 m_process_relation(other->m_process_relation),
12701266 m_select_relation_members(other->m_select_relation_members)
12711267{
1272- assert (m_db_connections.empty ());
1273-
12741268 for (auto &table : *m_tables) {
12751269 auto &tc = m_table_connections.emplace_back (&table, m_copy_thread);
1276- m_db_connections.emplace_back (get_options ()->connection_params ,
1277- " out.flex.table" );
1278- tc.prepare (m_db_connections.back ());
1270+ tc.prepare (m_db_connection);
12791271 }
12801272
12811273 for (auto &expire_output : *m_expire_outputs) {
@@ -1295,6 +1287,7 @@ output_flex_t::output_flex_t(std::shared_ptr<middle_query_t> const &mid,
12951287 std::shared_ptr<thread_pool_t > thread_pool,
12961288 options_t const &options)
12971289: output_t (mid, std::move(thread_pool), options),
1290+ m_db_connection (get_options()->connection_params, "out.flex.main"),
12981291 m_copy_thread(std::make_shared<db_copy_thread_t >(options.connection_params))
12991292{
13001293 init_lua (options.style );
@@ -1521,10 +1514,8 @@ void output_flex_t::reprocess_marked()
15211514 for (auto &table : m_table_connections) {
15221515 if (table.table ().matches_type (osmium::item_type::way) &&
15231516 table.table ().has_id_column ()) {
1524- auto const &db_connection =
1525- m_db_connections.at (table.table ().num ());
1526- table.analyze (db_connection);
1527- table.create_id_index (db_connection);
1517+ table.analyze (m_db_connection);
1518+ table.create_id_index (m_db_connection);
15281519 }
15291520 }
15301521
0 commit comments