Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use db_connection as param/var name #2165

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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