Skip to content

Commit

Permalink
Merge pull request #2165 from joto/rename-connection-param
Browse files Browse the repository at this point in the history
Consistently use db_connection as param/var name
  • Loading branch information
lonvia authored Apr 9, 2024
2 parents bd0b29a + 9e6deff commit 779406b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
11 changes: 6 additions & 5 deletions src/db-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include "pgsql.hpp"

void db_deleter_by_id_t::delete_rows(std::string const &table,
std::string const &column, pg_conn_t *conn)
std::string const &column,
pg_conn_t const &db_connection)
{
fmt::memory_buffer sql;
// Each deletable contributes an OSM ID and a comma. The highest node ID
Expand All @@ -32,12 +33,12 @@ void db_deleter_by_id_t::delete_rows(std::string const &table,
sql[sql.size() - 1] = ')';

sql.push_back('\0');
conn->exec(sql.data());
db_connection.exec(sql.data());
}

void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
std::string const &column,
pg_conn_t *conn)
pg_conn_t const &db_connection)
{
assert(!m_deletables.empty());

Expand Down Expand Up @@ -78,7 +79,7 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
}

sql.push_back('\0');
conn->exec(sql.data());
db_connection.exec(sql.data());
}

db_copy_thread_t::db_copy_thread_t(connection_params_t const &connection_params)
Expand Down Expand Up @@ -182,7 +183,7 @@ void db_copy_thread_t::thread_t::write_to_db(db_cmd_copy_t *buffer)
finish_copy();
}

buffer->delete_data(m_db_connection.get());
buffer->delete_data(*m_db_connection);

if (!m_inflight) {
start_copy(buffer->target);
Expand Down
10 changes: 5 additions & 5 deletions src/db-copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class db_deleter_by_id_t
void add(osmid_t osm_id) { m_deletables.push_back(osm_id); }

void delete_rows(std::string const &table, std::string const &column,
pg_conn_t *conn);
pg_conn_t const &db_connection);

bool is_full() const noexcept { return m_deletables.size() > Max_entries; }

Expand Down Expand Up @@ -126,7 +126,7 @@ class db_deleter_by_type_and_id_t
}

void delete_rows(std::string const &table, std::string const &column,
pg_conn_t *conn);
pg_conn_t const &db_connection);

bool is_full() const noexcept { return m_deletables.size() > Max_entries; }

Expand Down Expand Up @@ -183,7 +183,7 @@ struct db_cmd_copy_t : public db_cmd_t
std::string buffer;

virtual bool has_deletables() const noexcept = 0;
virtual void delete_data(pg_conn_t *conn) = 0;
virtual void delete_data(pg_conn_t const &db_connection) = 0;

explicit db_cmd_copy_t(std::shared_ptr<db_target_descr_t> t)
: db_cmd_t(db_cmd_t::Cmd_copy), target(std::move(t))
Expand All @@ -209,12 +209,12 @@ class db_cmd_copy_delete_t : public db_cmd_copy_t
return m_deleter.has_data();
}

void delete_data(pg_conn_t *conn) override
void delete_data(pg_conn_t const &db_connection) override
{
if (m_deleter.has_data()) {
m_deleter.delete_rows(
qualified_name(target->schema(), target->name()), target->id(),
conn);
db_connection);
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/expire-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,38 @@ std::size_t expire_output_t::output_tiles_to_table(
{
auto const qn = qualified_name(m_schema, m_table);

pg_conn_t connection{connection_params, "expire"};
pg_conn_t const db_connection{connection_params, "expire"};

auto const result = connection.exec("SELECT * FROM {} LIMIT 1", qn);
auto const result = db_connection.exec("SELECT * FROM {} LIMIT 1", qn);

if (result.num_fields() == 3) {
// old format with fields: zoom, x, y
connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
" ON CONFLICT DO NOTHING",
qn);
db_connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
" ON CONFLICT DO NOTHING",
qn);
} else {
// new format with fields: zoom, x, y, first, last
connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
" ON CONFLICT (zoom, x, y)"
" DO UPDATE SET last = CURRENT_TIMESTAMP(0)",
qn);
db_connection.exec("PREPARE insert_tiles(int4, int4, int4) AS"
" INSERT INTO {} (zoom, x, y) VALUES ($1, $2, $3)"
" ON CONFLICT (zoom, x, y)"
" DO UPDATE SET last = CURRENT_TIMESTAMP(0)",
qn);
}

auto const count = for_each_tile(
tiles_at_maxzoom, m_minzoom, m_maxzoom, [&](tile_t const &tile) {
connection.exec_prepared("insert_tiles", tile.zoom(), tile.x(),
tile.y());
db_connection.exec_prepared("insert_tiles", tile.zoom(), tile.x(),
tile.y());
});

return count;
}

void expire_output_t::create_output_table(pg_conn_t const &connection) const
void expire_output_t::create_output_table(pg_conn_t const &db_connection) const
{
auto const qn = qualified_name(m_schema, m_table);
connection.exec(
db_connection.exec(
"CREATE TABLE IF NOT EXISTS {} ("
" zoom int4 NOT NULL,"
" x int4 NOT NULL,"
Expand Down
2 changes: 1 addition & 1 deletion src/expire-output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class expire_output_t
/**
* Create table for tiles.
*/
void create_output_table(pg_conn_t const &connection) const;
void create_output_table(pg_conn_t const &db_connection) const;

private:
/// The filename (if any) for output
Expand Down

0 comments on commit 779406b

Please sign in to comment.