summaryrefslogtreecommitdiff
path: root/common/src/leap/soledad/common/ddocs
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-07-22 20:33:06 +0200
committerdrebs <drebs@leap.se>2016-08-01 21:08:56 -0300
commitc3e0f52080041e2a01cfa483efe73f8503a10f31 (patch)
tree08de4119fedaee6fa2e78f5357db805a16bea025 /common/src/leap/soledad/common/ddocs
parent2a57f749672580591b07065adde334029ddfb460 (diff)
[feat] remove usage of design documents in couch
Design documents are slow and we already have alternatives to all uses we used to make of them, so this commit completelly removes all usage of design documents.
Diffstat (limited to 'common/src/leap/soledad/common/ddocs')
-rw-r--r--common/src/leap/soledad/common/ddocs/README.txt34
-rw-r--r--common/src/leap/soledad/common/ddocs/docs/views/get/map.js20
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/updates/state.js105
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js20
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js11
-rw-r--r--common/src/leap/soledad/common/ddocs/syncs/views/state/map.js17
-rw-r--r--common/src/leap/soledad/common/ddocs/transactions/lists/generation.js20
-rw-r--r--common/src/leap/soledad/common/ddocs/transactions/lists/trans_id_for_gen.js19
-rw-r--r--common/src/leap/soledad/common/ddocs/transactions/lists/whats_changed.js22
-rw-r--r--common/src/leap/soledad/common/ddocs/transactions/views/log/map.js7
10 files changed, 0 insertions, 275 deletions
diff --git a/common/src/leap/soledad/common/ddocs/README.txt b/common/src/leap/soledad/common/ddocs/README.txt
deleted file mode 100644
index 5569d929..00000000
--- a/common/src/leap/soledad/common/ddocs/README.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-This directory holds a folder structure containing javascript files that
-represent the design documents needed by the CouchDB U1DB backend. These files
-are compiled into the `../ddocs.py` file by setuptools when creating the
-source distribution.
-
-The following table depicts the U1DB CouchDB backend method and the URI that
-is queried to obtain/update data from/to the server.
-
- +----------------------------------+------------------------------------------------------------------+
- | u1db backend method | URI |
- |----------------------------------+------------------------------------------------------------------|
- | _get_generation | _design/transactions/_list/generation/log |
- | _get_generation_info | _design/transactions/_list/generation/log |
- | _get_trans_id_for_gen | _design/transactions/_list/trans_id_for_gen/log |
- | _get_transaction_log | _design/transactions/_view/log |
- | _get_doc (*) | _design/docs/_view/get?key=<doc_id> |
- | _has_conflicts | _design/docs/_view/get?key=<doc_id> |
- | get_all_docs | _design/docs/_view/get |
- | _put_doc | _design/docs/_update/put/<doc_id> |
- | _whats_changed | _design/transactions/_list/whats_changed/log?old_gen=<gen> |
- | _get_conflicts (*) | _design/docs/_view/conflicts?key=<doc_id> |
- | _get_replica_gen_and_trans_id | _design/syncs/_view/log?other_replica_uid=<uid> |
- | _do_set_replica_gen_and_trans_id | _design/syncs/_update/put/u1db_sync_log |
- | _add_conflict | _design/docs/_update/add_conflict/<doc_id> |
- | _delete_conflicts | _design/docs/_update/delete_conflicts/<doc_id>?doc_rev=<doc_rev> |
- | list_indexes | not implemented |
- | _get_index_definition | not implemented |
- | delete_index | not implemented |
- | _get_indexed_fields | not implemented |
- | _put_and_update_indexes | not implemented |
- +----------------------------------+------------------------------------------------------------------+
-
-(*) These methods also request CouchDB document attachments that store U1DB
- document contents.
diff --git a/common/src/leap/soledad/common/ddocs/docs/views/get/map.js b/common/src/leap/soledad/common/ddocs/docs/views/get/map.js
deleted file mode 100644
index ae08d9e9..00000000
--- a/common/src/leap/soledad/common/ddocs/docs/views/get/map.js
+++ /dev/null
@@ -1,20 +0,0 @@
-function(doc) {
- if (doc.u1db_rev) {
- var is_tombstone = true;
- var has_conflicts = false;
- if (doc._attachments) {
- if (doc._attachments.u1db_content)
- is_tombstone = false;
- if (doc._attachments.u1db_conflicts)
- has_conflicts = true;
- }
- emit(doc._id,
- {
- "couch_rev": doc._rev,
- "u1db_rev": doc.u1db_rev,
- "is_tombstone": is_tombstone,
- "has_conflicts": has_conflicts,
- }
- );
- }
-}
diff --git a/common/src/leap/soledad/common/ddocs/syncs/updates/state.js b/common/src/leap/soledad/common/ddocs/syncs/updates/state.js
deleted file mode 100644
index d62aeb40..00000000
--- a/common/src/leap/soledad/common/ddocs/syncs/updates/state.js
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * This update handler stores information about ongoing synchronization
- * attempts from distinct source replicas.
- *
- * Normally, u1db synchronization occurs during one POST request. In order to
- * split that into many serial POST requests, we store the state of each sync
- * in the server, using a document with id 'u1db_sync_state'. To identify
- * each sync attempt, we use a sync_id sent by the client. If we ever receive
- * a new sync_id, we trash current data for that source replica and start
- * over.
- *
- * We expect the following in the document body:
- *
- * {
- * 'source_replica_uid': '<source_replica_uid>',
- * 'sync_id': '<sync_id>',
- * 'seen_ids': [['<doc_id>', <at_gen>], ...], // optional
- * 'changes_to_return': [ // optional
- * 'gen': <gen>,
- * 'trans_id': '<trans_id>',
- * 'changes_to_return': [[<doc_id>', <gen>, '<trans_id>'], ...]
- * ],
- * }
- *
- * The format of the final document stored on server is:
- *
- * {
- * '_id': '<str>',
- * '_rev' '<str>',
- * 'ongoing_syncs': {
- * '<source_replica_uid>': {
- * 'sync_id': '<sync_id>',
- * 'seen_ids': [['<doc_id>', <at_gen>[, ...],
- * 'changes_to_return': {
- * 'gen': <gen>,
- * 'trans_id': '<trans_id>',
- * 'changes_to_return': [
- * ['<doc_id>', <gen>, '<trans_id>'],
- * ...,
- * ],
- * },
- * },
- * ... // info about other source replicas here
- * }
- * }
- */
-function(doc, req) {
-
- // prevent updates to alien documents
- if (doc != null && doc['_id'] != 'u1db_sync_state')
- return [null, 'invalid data'];
-
- // create the document if it doesn't exist
- if (!doc)
- doc = {
- '_id': 'u1db_sync_state',
- 'ongoing_syncs': {},
- };
-
- // parse and validate incoming data
- var body = JSON.parse(req.body);
- if (body['source_replica_uid'] == null)
- 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]['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,
- };
-
- // incoming meta-data values should be exclusive, so we count how many
- // arrived and deny to accomplish the transaction if the count is high.
- var incoming_values = 0;
- var info = doc['ongoing_syncs'][source_replica_uid]
-
- // add incoming seen id
- if ('seen_id' in body) {
- info['seen_ids'][body['seen_id'][0]] = body['seen_id'][1];
- incoming_values += 1;
- }
-
- // add incoming changes_to_return
- if ('changes_to_return' in body) {
- info['changes_to_return'] = body['changes_to_return'];
- incoming_values += 1;
- }
-
- if (incoming_values != 1)
- return [null, 'invalid data'];
-
- return [doc, 'ok'];
-}
-
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
deleted file mode 100644
index 94b7e767..00000000
--- a/common/src/leap/soledad/common/ddocs/syncs/views/changes_to_return/map.js
+++ /dev/null
@@ -1,20 +0,0 @@
-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, sync_id, 0], null);
- else if (changes.length == 0)
- emit([source_replica_uid, sync_id, 0], []);
- else
- for (var i = 0; i < changes['changes_to_return'].length; i++)
- emit(
- [source_replica_uid, sync_id, i],
- {
- 'gen': changes['gen'],
- 'trans_id': changes['trans_id'],
- 'next_change_to_return': changes['changes_to_return'][i],
- });
- }
-}
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
deleted file mode 100644
index 16118e88..00000000
--- a/common/src/leap/soledad/common/ddocs/syncs/views/seen_ids/map.js
+++ /dev/null
@@ -1,11 +0,0 @@
-function(doc) {
- if (doc['_id'] == 'u1db_sync_state' && doc['ongoing_syncs'] != null)
- for (var source_replica_uid in doc['ongoing_syncs']) {
- var sync_id = doc['ongoing_syncs'][source_replica_uid]['sync_id'];
- emit(
- [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
deleted file mode 100644
index e88c6ebb..00000000
--- a/common/src/leap/soledad/common/ddocs/syncs/views/state/map.js
+++ /dev/null
@@ -1,17 +0,0 @@
-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, sync_id], null);
- else
- emit(
- [source_replica_uid, sync_id],
- {
- 'gen': changes['gen'],
- 'trans_id': changes['trans_id'],
- 'number_of_changes': changes['changes_to_return'].length
- });
- }
-}
diff --git a/common/src/leap/soledad/common/ddocs/transactions/lists/generation.js b/common/src/leap/soledad/common/ddocs/transactions/lists/generation.js
deleted file mode 100644
index dbdfff0d..00000000
--- a/common/src/leap/soledad/common/ddocs/transactions/lists/generation.js
+++ /dev/null
@@ -1,20 +0,0 @@
-function(head, req) {
- var row;
- var rows=[];
- // fetch all rows
- while(row = getRow()) {
- rows.push(row);
- }
- if (rows.length > 0)
- send(JSON.stringify({
- "generation": rows.length,
- "doc_id": rows[rows.length-1]['id'],
- "transaction_id": rows[rows.length-1]['value']
- }));
- else
- send(JSON.stringify({
- "generation": 0,
- "doc_id": "",
- "transaction_id": "",
- }));
-}
diff --git a/common/src/leap/soledad/common/ddocs/transactions/lists/trans_id_for_gen.js b/common/src/leap/soledad/common/ddocs/transactions/lists/trans_id_for_gen.js
deleted file mode 100644
index 2ec91794..00000000
--- a/common/src/leap/soledad/common/ddocs/transactions/lists/trans_id_for_gen.js
+++ /dev/null
@@ -1,19 +0,0 @@
-function(head, req) {
- var row;
- var rows=[];
- var i = 1;
- var gen = 1;
- if (req.query.gen)
- gen = parseInt(req.query['gen']);
- // fetch all rows
- while(row = getRow())
- rows.push(row);
- if (gen <= rows.length)
- send(JSON.stringify({
- "generation": gen,
- "doc_id": rows[gen-1]['id'],
- "transaction_id": rows[gen-1]['value'],
- }));
- else
- send('{}');
-}
diff --git a/common/src/leap/soledad/common/ddocs/transactions/lists/whats_changed.js b/common/src/leap/soledad/common/ddocs/transactions/lists/whats_changed.js
deleted file mode 100644
index b35cdf51..00000000
--- a/common/src/leap/soledad/common/ddocs/transactions/lists/whats_changed.js
+++ /dev/null
@@ -1,22 +0,0 @@
-function(head, req) {
- var row;
- var gen = 1;
- var old_gen = 0;
- if (req.query.old_gen)
- old_gen = parseInt(req.query['old_gen']);
- send('{"transactions":[\n');
- // fetch all rows
- while(row = getRow()) {
- if (gen > old_gen) {
- if (gen > old_gen+1)
- send(',\n');
- send(JSON.stringify({
- "generation": gen,
- "doc_id": row["id"],
- "transaction_id": row["value"]
- }));
- }
- gen++;
- }
- send('\n]}');
-}
diff --git a/common/src/leap/soledad/common/ddocs/transactions/views/log/map.js b/common/src/leap/soledad/common/ddocs/transactions/views/log/map.js
deleted file mode 100644
index 94ef63ca..00000000
--- a/common/src/leap/soledad/common/ddocs/transactions/views/log/map.js
+++ /dev/null
@@ -1,7 +0,0 @@
-function(doc) {
- if (doc.u1db_transactions)
- doc.u1db_transactions.forEach(function(t) {
- emit(t[0], // use timestamp as key so the results are ordered
- t[1]); // value is the transaction_id
- });
-}