-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbreplicate.cpp
More file actions
103 lines (84 loc) · 3.37 KB
/
dbreplicate.cpp
File metadata and controls
103 lines (84 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "dbreplicate.h"
#include "dbdecode.h"
#include <set>
using namespace std;
void GetReplicateDiffNodes(pqxx::connection &c, pqxx::transaction_base *work, class DbUsernameLookup &usernames,
const string &tablePrefix,
bool selectOld,
int64_t timestampStart, int64_t timestampEnd,
class OsmChange &out)
{
string nodeTable = c.quote_name(tablePrefix + "livenodes");
if(selectOld)
nodeTable = c.quote_name(tablePrefix + "oldnodes");
//Discourage sequential scans of tables, since they is not necessary and we want to avoid doing a sort
work->exec("set enable_seqscan to off;");
stringstream sql;
sql << "SELECT "<< nodeTable << ".*, ST_X(geom) as lon, ST_Y(geom) AS lat FROM ";
sql << nodeTable;
sql << " WHERE timestamp > " << timestampStart << " AND timestamp <= " << timestampEnd;
sql << " ORDER BY " << nodeTable << ".timestamp;";
pqxx::icursorstream cursor( *work, sql.str(), "nodediff", 1000 );
std::shared_ptr<class OsmData> data = make_shared<class OsmData>();
int count = 1;
while(count > 0)
count = NodeResultsToEncoder(cursor, usernames, data);
for(size_t i=0; i < data->nodes.size(); i++)
{
const class OsmObject &obj = data->nodes[i];
out.StoreOsmData(&obj, false);
}
}
void GetReplicateDiffWays(pqxx::connection &c, pqxx::transaction_base *work, class DbUsernameLookup &usernames,
const string &tablePrefix,
bool selectOld,
int64_t timestampStart, int64_t timestampEnd,
class OsmChange &out)
{
string wayTable = c.quote_name(tablePrefix + "liveways");
if(selectOld)
wayTable = c.quote_name(tablePrefix + "oldways");
//Discourage sequential scans of tables, since they is not necessary and we want to avoid doing a sort
work->exec("set enable_seqscan to off;");
stringstream sql;
sql << "SELECT " << wayTable << ".* FROM ";
sql << wayTable;
sql << " WHERE timestamp > " << timestampStart << " AND timestamp <= " << timestampEnd;
sql << " ORDER BY " << wayTable << ".timestamp;";
pqxx::icursorstream cursor( *work, sql.str(), "waydiff", 1000 );
std::shared_ptr<class OsmData> data = make_shared<class OsmData>();
int count = 1;
while (count > 0)
count = WayResultsToEncoder(cursor, usernames, data);
for(size_t i=0; i < data->ways.size(); i++)
{
const class OsmObject &obj = data->ways[i];
out.StoreOsmData(&obj, false);
}
}
void GetReplicateDiffRelations(pqxx::connection &c, pqxx::transaction_base *work, class DbUsernameLookup &usernames,
const string &tablePrefix,
bool selectOld,
int64_t timestampStart, int64_t timestampEnd,
class OsmChange &out)
{
string relationTable = c.quote_name(tablePrefix + "liverelations");
if(selectOld)
relationTable = c.quote_name(tablePrefix + "oldrelations");
//Discourage sequential scans of tables, since they is not necessary and we want to avoid doing a sort
work->exec("set enable_seqscan to off;");
stringstream sql;
sql << "SELECT " << relationTable << ".* FROM ";
sql << relationTable;
sql << " WHERE timestamp > " << timestampStart << " AND timestamp <= " << timestampEnd;
sql << " ORDER BY " << relationTable << ".timestamp;";
pqxx::icursorstream cursor( *work, sql.str(), "relationdiff", 1000 );
std::shared_ptr<class OsmData> data = make_shared<class OsmData>();
set<int64_t> empty;
RelationResultsToEncoder(cursor, usernames, empty, data);
for(size_t i=0; i < data->relations.size(); i++)
{
const class OsmObject &obj = data->relations[i];
out.StoreOsmData(&obj, false);
}
}