Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
fix: Queries is now a vector of SQL strings
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed May 20, 2024
1 parent f7b9cb0 commit e64ab97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
52 changes: 39 additions & 13 deletions src/bootstrap/bootstrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ BootstrapQueries
Bootstrap::allTasksQueries(std::shared_ptr<std::vector<BootstrapTask>> tasks) {
BootstrapQueries queries;
for (auto it = tasks->begin(); it != tasks->end(); ++it) {
queries.underpass += it->query ;
queries.osm += it->osmquery ;
for (auto itt = it->query.begin(); itt != it->query.end(); ++itt) {
queries.underpass.push_back(*itt);
}
for (auto itt = it->osmquery.begin(); itt != it->osmquery.end(); ++itt) {
queries.osm.push_back(*itt);
}
}
return queries;
}
Expand Down Expand Up @@ -154,8 +158,12 @@ Bootstrap::processWays() {

auto queries = allTasksQueries(tasks);

db->query(queries.underpass);
osmdb->query(queries.osm);
for (auto it = queries.underpass.begin(); it != queries.underpass.end(); ++it) {
db->query(*it);
}
for (auto it = queries.osm.begin(); it != queries.osm.end(); ++it) {
osmdb->query(*it);
}

lastid = ways->back().id;
for (auto it = tasks->begin(); it != tasks->end(); ++it) {
Expand Down Expand Up @@ -206,8 +214,12 @@ Bootstrap::processNodes() {
pool.join();

auto queries = allTasksQueries(tasks);
db->query(queries.underpass);
osmdb->query(queries.osm);
for (auto it = queries.underpass.begin(); it != queries.underpass.end(); ++it) {
db->query(*it);
}
for (auto it = queries.osm.begin(); it != queries.osm.end(); ++it) {
osmdb->query(*it);
}
lastid = nodes->back().id;
for (auto it = tasks->begin(); it != tasks->end(); ++it) {
count += it->processed;
Expand Down Expand Up @@ -256,9 +268,12 @@ Bootstrap::processRelations() {
pool.join();

auto queries = allTasksQueries(tasks);
db->query(queries.underpass);
osmdb->query(queries.osm);

for (auto it = queries.underpass.begin(); it != queries.underpass.end(); ++it) {
db->query(*it);
}
for (auto it = queries.osm.begin(); it != queries.osm.end(); ++it) {
osmdb->query(*it);
}
lastid = relations->back().id;
for (auto it = tasks->begin(); it != tasks->end(); ++it) {
count += it->processed;
Expand Down Expand Up @@ -295,13 +310,19 @@ Bootstrap::threadBootstrapWayTask(WayTask wayTask)
// Fill the way_refs table
if (!norefs) {
for (auto ref = way.refs.begin(); ref != way.refs.end(); ++ref) {
task.osmquery += "INSERT INTO way_refs (way_id, node_id) VALUES (" + std::to_string(way.id) + "," + std::to_string(*ref) + "); ";
task.osmquery.push_back("INSERT INTO way_refs (way_id, node_id) VALUES (" + std::to_string(way.id) + "," + std::to_string(*ref) + "); ");
}
}
++processed;
}
}
queryvalidate->ways(wayval, task.query);

auto result = queryvalidate->ways(wayval);
for (auto it = result->begin(); it != result->end(); ++it) {
task.query.push_back(*it);
log_debug("FOO: %1%", *it);
}

task.processed = processed;
const std::lock_guard<std::mutex> lock(tasks_change_mutex);
(*tasks)[taskIndex] = task;
Expand Down Expand Up @@ -337,7 +358,12 @@ Bootstrap::threadBootstrapNodeTask(NodeTask nodeTask)
++processed;
}
}
queryvalidate->nodes(nodeval, task.query);

auto result = queryvalidate->nodes(nodeval);
for (auto it = result->begin(); it != result->end(); ++it) {
task.query.push_back(*it);
}

task.processed = processed;
const std::lock_guard<std::mutex> lock(tasks_change_mutex);
(*tasks)[taskIndex] = task;
Expand Down Expand Up @@ -367,7 +393,7 @@ Bootstrap::threadBootstrapRelationTask(RelationTask relationTask)
// relationval->push_back(validator->checkRelation(way, "building"));
// Fill the rel_refs table
for (auto mit = relation.members.begin(); mit != relation.members.end(); ++mit) {
task.osmquery += "INSERT INTO rel_refs (rel_id, way_id) VALUES (" + std::to_string(relation.id) + "," + std::to_string(mit->ref) + "); ";
task.osmquery.push_back("INSERT INTO rel_refs (rel_id, way_id) VALUES (" + std::to_string(relation.id) + "," + std::to_string(mit->ref) + "); ");
}
++processed;
}
Expand Down
9 changes: 4 additions & 5 deletions src/bootstrap/bootstrap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ namespace bootstrap {
/// \struct BootstrapTask
/// \brief Represents a bootstrap task
struct BootstrapTask {
std::string query = "";
std::string osmquery = "";
std::vector<std::string> query;
std::vector<std::string> osmquery;
int processed = 0;
};

/// \struct BootstrapQueries
/// \brief Represents a bootstrap queries list
struct BootstrapQueries {
std::string underpass = "";
std::string osm = "";
std::vector<std::string> underpass;
std::vector<std::string> osm;
};


struct WayTask {
int taskIndex;
std::shared_ptr<std::vector<BootstrapTask>> tasks;
Expand Down

0 comments on commit e64ab97

Please sign in to comment.