Skip to content

Commit

Permalink
Merge pull request #2148 from joto/cleanup-flex-table
Browse files Browse the repository at this point in the history
Move analyze() and prepare() from table_connection_t to flex_table_t
  • Loading branch information
lonvia authored Mar 28, 2024
2 parents 664681d + 7486cdb commit 37e12e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions src/flex-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ bool flex_table_t::has_columns_with_expire() const noexcept
[](auto const &column) { return column.has_expire(); });
}

void flex_table_t::prepare(pg_conn_t const &db_connection) const
{
if (has_id_column() && has_columns_with_expire()) {
db_connection.exec(build_sql_prepare_get_wkb());
}
}

void flex_table_t::analyze(pg_conn_t const &db_connection) const
{
analyze_table(db_connection, schema(), name());
}

static void enable_check_trigger(pg_conn_t const &db_connection,
flex_table_t const &table)
{
Expand Down Expand Up @@ -285,7 +297,7 @@ void table_connection_t::start(pg_conn_t const &db_connection, bool append)
enable_check_trigger(db_connection, table());
}

prepare(db_connection);
table().prepare(db_connection);
}

void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable,
Expand Down Expand Up @@ -368,19 +380,7 @@ void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable,
}

log_info("Analyzing table '{}'...", table().name());
analyze(db_connection);
}

void table_connection_t::prepare(pg_conn_t const &db_connection)
{
if (table().has_id_column() && table().has_columns_with_expire()) {
db_connection.exec(table().build_sql_prepare_get_wkb());
}
}

void table_connection_t::analyze(pg_conn_t const &db_connection)
{
analyze_table(db_connection, table().schema(), table().name());
table().analyze(db_connection);
}

void table_connection_t::create_id_index(pg_conn_t const &db_connection)
Expand Down
8 changes: 4 additions & 4 deletions src/flex-table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ class flex_table_t

std::size_t num() const noexcept { return m_table_num; }

void prepare(pg_conn_t const &db_connection) const;

void analyze(pg_conn_t const &db_connection) const;

private:
/// The schema this table is in
std::string m_schema;
Expand Down Expand Up @@ -270,10 +274,6 @@ class table_connection_t

flex_table_t const &table() const noexcept { return *m_table; }

void prepare(pg_conn_t const &db_connection);

void analyze(pg_conn_t const &db_connection);

void create_id_index(pg_conn_t const &db_connection);

/**
Expand Down
6 changes: 3 additions & 3 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,8 @@ output_flex_t::output_flex_t(output_flex_t const *other,
m_select_relation_members(other->m_select_relation_members)
{
for (auto &table : *m_tables) {
auto &tc = m_table_connections.emplace_back(&table, m_copy_thread);
tc.prepare(m_db_connection);
table.prepare(m_db_connection);
m_table_connections.emplace_back(&table, m_copy_thread);
}

for (auto &expire_output : *m_expire_outputs) {
Expand Down Expand Up @@ -1514,7 +1514,7 @@ 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()) {
table.analyze(m_db_connection);
table.table().analyze(m_db_connection);
table.create_id_index(m_db_connection);
}
}
Expand Down

0 comments on commit 37e12e0

Please sign in to comment.