summaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-06-03 18:43:56 -0300
committerdrebs <drebs@leap.se>2014-06-05 10:45:29 -0300
commit7d9d827a5f66993863ca0c532c01ad3bf2c4353e (patch)
treed712d632a339cb6865e5aa38110f7b56c5f1b7db /common/src
parenta0cbdc8bbba4369c20bb5b285e464c23d6954e17 (diff)
Replace client sync state by a sync_id.
Diffstat (limited to 'common/src')
-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'],