From a2fd45f57a9d6cfed2d5a4143c11c9efc063395a Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 2 Jan 2025 20:59:02 +0100 Subject: [PATCH] Refactor: Remove m_users_table member variable Making the code simpler. --- src/middle-pgsql.cpp | 23 +++++++++++------------ src/middle-pgsql.hpp | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/middle-pgsql.cpp b/src/middle-pgsql.cpp index 4e965a1cc..499e5a785 100644 --- a/src/middle-pgsql.cpp +++ b/src/middle-pgsql.cpp @@ -1086,10 +1086,12 @@ void middle_pgsql_t::start() void middle_pgsql_t::write_users_table() { - log_info("Writing {} entries to table '{}'...", m_users.size(), - m_users_table.name()); + auto const table_name = m_options->prefix + "_users"; + + log_info("Writing {} entries to table '{}'...", m_users.size(), table_name); + auto const users_table = std::make_shared( - m_users_table.schema(), m_users_table.name(), "id"); + m_options->dbschema, table_name, "id"); for (auto const &[id, name] : m_users) { m_db_copy.new_line(users_table); @@ -1100,20 +1102,20 @@ void middle_pgsql_t::write_users_table() m_users.clear(); - analyze_table(m_db_connection, m_users_table.schema(), - m_users_table.name()); + analyze_table(m_db_connection, m_options->dbschema, table_name); } void middle_pgsql_t::update_users_table() { - log_info("Writing {} entries to table '{}'...", m_users.size(), - m_users_table.name()); + auto const table_name = m_options->prefix + "_users"; + + log_info("Writing {} entries to table '{}'...", m_users.size(), table_name); m_db_connection.prepare( "insert_user", "INSERT INTO {}.\"{}\" (id, name) VALUES ($1::int8, $2::text)" " ON CONFLICT (id) DO UPDATE SET id=EXCLUDED.id", - m_users_table.schema(), m_users_table.name()); + m_options->dbschema, table_name); for (auto const &[id, name] : m_users) { m_db_connection.exec_prepared("insert_user", id, name); @@ -1121,8 +1123,7 @@ void middle_pgsql_t::update_users_table() m_users.clear(); - analyze_table(m_db_connection, m_users_table.schema(), - m_users_table.name()); + analyze_table(m_db_connection, m_options->dbschema, table_name); } void middle_pgsql_t::stop() @@ -1272,8 +1273,6 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr thread_pool, m_tables.nodes() = table_desc{*options, "nodes"}; m_tables.ways() = table_desc{*options, "ways"}; m_tables.relations() = table_desc{*options, "rels"}; - - m_users_table = table_desc{*options, "users"}; } void middle_pgsql_t::set_requirements( diff --git a/src/middle-pgsql.hpp b/src/middle-pgsql.hpp index 238b08cc7..1df054d81 100644 --- a/src/middle-pgsql.hpp +++ b/src/middle-pgsql.hpp @@ -178,7 +178,6 @@ struct middle_pgsql_t : public middle_t std::map m_users; osmium::nwr_array m_tables; - table_desc m_users_table; options_t const *m_options;