Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Remove changeset cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mmd-osm committed Jul 11, 2022
1 parent aebd60a commit 42a2883
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 321 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ if ENABLE_APIDB
cgimap_apidb_includedir=$(includedir)/cgimap/backend/apidb
cgimap_apidb_include_HEADERS = \
include/cgimap/backend/apidb/apidb.hpp \
include/cgimap/backend/apidb/cache.hpp \
include/cgimap/backend/apidb/changeset.hpp \
include/cgimap/backend/apidb/quad_tile.hpp \
include/cgimap/backend/apidb/readonly_pgsql_selection.hpp \
Expand Down
205 changes: 0 additions & 205 deletions include/cgimap/backend/apidb/cache.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion include/cgimap/backend/apidb/changeset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ struct changeset {
std::string display_name;
osm_user_id_t user_id;

changeset() = default;

changeset(bool dp, const std::string &dn, osm_user_id_t id);
};

std::map<osm_changeset_id_t, changeset *> fetch_changesets(pqxx::transaction_base &w, std::set<osm_changeset_id_t> id);


#endif /* CHANGESET_HPP */
9 changes: 4 additions & 5 deletions include/cgimap/backend/apidb/common_pgsql_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define CGIMAP_BACKEND_APIDB_COMMON_PGSQL_SELECTION_HPP

#include <cgimap/output_formatter.hpp>
#include <cgimap/backend/apidb/cache.hpp>
#include <cgimap/backend/apidb/changeset.hpp>

#include <chrono>
Expand All @@ -18,25 +17,25 @@
void extract_nodes(
const pqxx::result &rows, output_formatter &formatter,
std::function<void(const element_info&)> notify,
cache<osm_changeset_id_t, changeset> &cc);
std::map<osm_changeset_id_t, changeset> &cc);

// extract ways from the results of the query and write them to the formatter.
// the changeset cache is used to look up user display names.
void extract_ways(
const pqxx::result &rows, output_formatter &formatter,
std::function<void(const element_info&)> notify,
cache<osm_changeset_id_t, changeset> &cc);
std::map<osm_changeset_id_t, changeset> &cc);

// extract relations from the results of the query and write them to the
// formatter. the changeset cache is used to look up user display names.
void extract_relations(
const pqxx::result &rows, output_formatter &formatter,
std::function<void(const element_info&)> notify,
cache<osm_changeset_id_t, changeset> &cc);
std::map<osm_changeset_id_t, changeset> &cc);

void extract_changesets(
const pqxx::result &rows, output_formatter &formatter,
cache<osm_changeset_id_t, changeset> &cc,
std::map<osm_changeset_id_t, changeset> &cc,
const std::chrono::system_clock::time_point &now,
bool include_changeset_discussions);

Expand Down
1 change: 0 additions & 1 deletion include/cgimap/backend/apidb/pgsql_update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "cgimap/data_update.hpp"
#include "cgimap/backend/apidb/changeset.hpp"
#include "cgimap/backend/apidb/cache.hpp"
#include "cgimap/backend/apidb/transaction_manager.hpp"

#include <memory>
Expand Down
19 changes: 11 additions & 8 deletions include/cgimap/backend/apidb/readonly_pgsql_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "cgimap/data_selection.hpp"
#include "cgimap/backend/apidb/changeset.hpp"
#include "cgimap/backend/apidb/cache.hpp"
#include "cgimap/backend/apidb/transaction_manager.hpp"

#include <pqxx/pqxx>
Expand All @@ -20,9 +19,10 @@
* stored in-memory in cgimap's memory.
*/
class readonly_pgsql_selection : public data_selection {


public:
readonly_pgsql_selection(Transaction_Owner_Base& to,
cache<osm_changeset_id_t, changeset> &changeset_cache);
readonly_pgsql_selection(Transaction_Owner_Base& to);
~readonly_pgsql_selection();

void write_nodes(output_formatter &formatter) override;
Expand Down Expand Up @@ -67,6 +67,8 @@ class readonly_pgsql_selection : public data_selection {
bool is_user_blocked(const osm_user_id_t) override;
bool get_user_id_pass(const std::string&, osm_user_id_t &, std::string &, std::string &) override;



/**
* a factory for the creation of read-only selections
*/
Expand All @@ -78,13 +80,14 @@ class readonly_pgsql_selection : public data_selection {
std::unique_ptr<Transaction_Owner_Base> get_default_transaction() override;

private:
pqxx::connection m_connection, m_cache_connection;
pqxx::quiet_errorhandler m_errorhandler, m_cache_errorhandler;
pqxx::nontransaction m_cache_tx;
cache<osm_changeset_id_t, changeset> m_cache;
pqxx::connection m_connection;
pqxx::quiet_errorhandler m_errorhandler;
};

private:
std::set< osm_changeset_id_t > extract_changeset_ids(pqxx::result& result);
void fetch_changesets(const std::set< osm_changeset_id_t >& ids, std::map<osm_changeset_id_t, changeset> & cc);

Transaction_Manager m;

// true if we want to include changeset discussions along with
Expand All @@ -99,7 +102,7 @@ class readonly_pgsql_selection : public data_selection {
std::set<osm_changeset_id_t> sel_changesets;
std::set<osm_nwr_id_t> sel_nodes, sel_ways, sel_relations;
std::set<osm_edition_t> sel_historic_nodes, sel_historic_ways, sel_historic_relations;
cache<osm_changeset_id_t, changeset> & cc;
std::map<osm_changeset_id_t, changeset> cc;
};

#endif /* READONLY_PGSQL_SELECTION_HPP */
2 changes: 0 additions & 2 deletions src/backend/apidb/apidb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ struct apidb_backend : public backend {
"database character set")
("readonly", "(obsolete parameter, read only backend is always assumed)")
("disable-api-write", "disable API write operations")
("cachesize", po::value<size_t>()->default_value(100000),
"maximum size of changeset cache")
("dbport", po::value<string>(),
"database port number or UNIX socket file name")
("oauth-dbname", po::value<string>(),
Expand Down
53 changes: 0 additions & 53 deletions src/backend/apidb/changeset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,5 @@ using std::string;
changeset::changeset(bool dp, const string &dn, osm_user_id_t id)
: data_public(dp), display_name(dn), user_id(id) {}

std::map<osm_changeset_id_t, changeset *> fetch_changesets(pqxx::transaction_base &w, std::set< osm_changeset_id_t > ids) {

std::map<osm_changeset_id_t, changeset*> result;

if (ids.empty())
return result;

w.conn().prepare("extract_changeset_userdetails",
"SELECT c.id, u.data_public, u.display_name, u.id from users u "
"join changesets c on u.id=c.user_id where c.id = ANY($1)");

pqxx::result res = w.exec_prepared("extract_changeset_userdetails", ids);

for (const auto & r : res) {

osm_changeset_id_t cs = r[0].as<int64_t>();

// Multiple results for one changeset?
if (result.find(cs) != result.end()) {
logger::message(
fmt::format("ERROR: Request for user data associated with changeset {:d} failed: returned multiple rows.", cs));
throw http::server_error(
fmt::format("Possible database inconsistency with changeset {:d}.", cs));
}

int64_t user_id = r[3].as<int64_t>();
// apidb instances external to OSM don't have access to anonymous
// user information and so use an ID which isn't in use for any
// other user to indicate this - generally 0 or negative.
if (user_id <= 0) {
result.insert(std::pair<osm_changeset_id_t, changeset*>(cs, new changeset(false, "", 0)));
} else {
result.insert(std::pair<osm_changeset_id_t, changeset*>(cs,
new changeset(r[1].as<bool>(), r[2].as<string>(), osm_user_id_t(user_id))));
}
}

// although the above query should always return one row, it might
// happen that we get a weird changeset ID from somewhere, or the
// FK constraints might have failed. in this situation all we can
// really do is whine loudly and bail.

// Missing changeset in query result?
for (const auto & id : ids) {
if (result.find(id) == result.end()) {
logger::message(
fmt::format("ERROR: Request for user data associated with changeset {:d} failed: returned 0 rows.", id));
throw http::server_error(
fmt::format("Possible database inconsistency with changeset {:d}.", id));
}
}

return result;
}

Loading

0 comments on commit 42a2883

Please sign in to comment.