summaryrefslogtreecommitdiff
path: root/common/src/leap/soledad
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/leap/soledad')
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/updates/state.js10
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js7
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js6
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/state/map.js5
4 files changed, 19 insertions, 9 deletions
diff --git a/common/src/leap/soledad/common/ddocs/syncs/updates/state.js b/common/src/leap/soledad/common/ddocs/syncs/updates/state.js
index cb2b6b7b..d62aeb40 100644
--- a/common/src/leap/soledad/common/ddocs/syncs/updates/state.js
+++ b/common/src/leap/soledad/common/ddocs/syncs/updates/state.js
@@ -29,6 +29,7 @@
* '_rev' '<str>',
* 'ongoing_syncs': {
* '<source_replica_uid>': {
+ * 'sync_id': '<sync_id>',
* 'seen_ids': [['<doc_id>', <at_gen>[, ...],
* 'changes_to_return': {
* 'gen': <gen>,
@@ -59,17 +60,22 @@ function(doc, req) {
// parse and validate incoming data
var body = JSON.parse(req.body);
if (body['source_replica_uid'] == null)
- return [null, 'invalid data']
+ return [null, 'invalid data'];
var source_replica_uid = body['source_replica_uid'];
+ if (body['sync_id'] == null)
+ return [null, 'invalid data'];
+ var sync_id = body['sync_id'];
+
// trash outdated sync data for that replica if that exists
if (doc['ongoing_syncs'][source_replica_uid] != null &&
- doc['ongoing_syncs'][source_replica_uid] == null)
+ doc['ongoing_syncs'][source_replica_uid]['sync_id'] != sync_id)
delete doc['ongoing_syncs'][source_replica_uid];
// create an entry for that source replica
if (doc['ongoing_syncs'][source_replica_uid] == null)
doc['ongoing_syncs'][source_replica_uid] = {
+ 'sync_id': sync_id,
'seen_ids': {},
'changes_to_return': null,
};
diff --git a/common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js b/common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js
index 04ceb2ec..94b7e767 100644
--- a/common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js
+++ b/common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js
@@ -2,14 +2,15 @@ function(doc) {
if (doc['_id'] == 'u1db_sync_state' && doc['ongoing_syncs'] != null)
for (var source_replica_uid in doc['ongoing_syncs']) {
var changes = doc['ongoing_syncs'][source_replica_uid]['changes_to_return'];
+ var sync_id = doc['ongoing_syncs'][source_replica_uid]['sync_id'];
if (changes == null)
- emit([source_replica_uid, 0], null);
+ emit([source_replica_uid, sync_id, 0], null);
else if (changes.length == 0)
- emit([source_replica_uid, 0], []);
+ emit([source_replica_uid, sync_id, 0], []);
else
for (var i = 0; i < changes['changes_to_return'].length; i++)
emit(
- [source_replica_uid, i],
+ [source_replica_uid, sync_id, i],
{
'gen': changes['gen'],
'trans_id': changes['trans_id'],
diff --git a/common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js b/common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js
index 34c65b3f..16118e88 100644
--- a/common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js
+++ b/common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js
@@ -1,9 +1,11 @@
function(doc) {
if (doc['_id'] == 'u1db_sync_state' && doc['ongoing_syncs'] != null)
- for (var source_replica_uid in doc['ongoing_syncs'])
+ for (var source_replica_uid in doc['ongoing_syncs']) {
+ var sync_id = doc['ongoing_syncs'][source_replica_uid]['sync_id'];
emit(
- source_replica_uid,
+ [source_replica_uid, sync_id],
{
'seen_ids': doc['ongoing_syncs'][source_replica_uid]['seen_ids'],
});
+ }
}
diff --git a/common/src/leap/soledad/common/ddocs/syncs/views/state/map.js b/common/src/leap/soledad/common/ddocs/syncs/views/state/map.js
index 1d8f8e84..e88c6ebb 100644
--- a/common/src/leap/soledad/common/ddocs/syncs/views/state/map.js
+++ b/common/src/leap/soledad/common/ddocs/syncs/views/state/map.js
@@ -2,11 +2,12 @@ function(doc) {
if (doc['_id'] == 'u1db_sync_state' && doc['ongoing_syncs'] != null)
for (var source_replica_uid in doc['ongoing_syncs']) {
var changes = doc['ongoing_syncs'][source_replica_uid]['changes_to_return'];
+ var sync_id = doc['ongoing_syncs'][source_replica_uid]['sync_id'];
if (changes == null)
- emit(source_replica_uid, null);
+ emit([source_replica_uid, sync_id], null);
else
emit(
- source_replica_uid,
+ [source_replica_uid, sync_id],
{
'gen': changes['gen'],
'trans_id': changes['trans_id'],