Merge lp:~pedronis/u1db/naming-in-sync-doc-json-envelope into lp:u1db

Proposed by Samuele Pedroni
Status: Merged
Approved by: John A Meinel
Approved revision: 138
Merged at revision: 138
Proposed branch: lp:~pedronis/u1db/naming-in-sync-doc-json-envelope
Merge into: lp:u1db
Diff against target: 63 lines (+7/-7)
3 files modified
u1db/remote/http_app.py (+3/-3)
u1db/remote/http_target.py (+2/-2)
u1db/tests/test_http_app.py (+2/-2)
To merge this branch: bzr merge lp:~pedronis/u1db/naming-in-sync-doc-json-envelope
Reviewer Review Type Date Requested Status
John A Meinel (community) Approve
Review via email: mp+84180@code.launchpad.net

Description of the change

use the more consistent naming 'content' not 'doc' for the main data field in the json object entries exchanged by sync for each document, right now we pass documents as strings (because is the natural thing with the current layering of things, and the current Document interface)

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Thanks. There are still a few places in the code where it would be good to do this. (Eg. u1db.tests.simple_doc)

I like sending the content as strings, so that we don't change the actual content. It would be nice to preserve:
PUT_DOC(id, content)
sha1(content) == sha1(GET_DOC(id))

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1db/remote/http_app.py'
2--- u1db/remote/http_app.py 2011-12-01 14:20:34 +0000
3+++ u1db/remote/http_app.py 2011-12-01 21:57:23 +0000
4@@ -289,13 +289,13 @@
5 self.sync_exch = self.target.get_sync_exchange()
6
7 @http_method(content_as_args=True)
8- def post_stream_entry(self, id, rev, doc):
9- doc = Document(id, rev, doc)
10+ def post_stream_entry(self, id, rev, content):
11+ doc = Document(id, rev, content)
12 self.sync_exch.insert_doc_from_source(doc)
13
14 def post_end(self):
15 def send_doc(doc):
16- entry = dict(id=doc.doc_id, rev=doc.rev, doc=doc.content)
17+ entry = dict(id=doc.doc_id, rev=doc.rev, content=doc.content)
18 self.responder.stream_entry(entry)
19 new_gen = self.sync_exch.find_docs_to_return(self.last_known_generation)
20 self.responder.content_type = 'application/x-u1db-multi-json'
21
22=== modified file 'u1db/remote/http_target.py'
23--- u1db/remote/http_target.py 2011-11-21 14:32:17 +0000
24+++ u1db/remote/http_target.py 2011-12-01 21:57:23 +0000
25@@ -60,7 +60,7 @@
26 size += prepare(last_known_generation=last_known_generation,
27 from_replica_generation=from_replica_generation)
28 for doc in docs:
29- size += prepare(id=doc.doc_id, rev=doc.rev, doc=doc.content)
30+ size += prepare(id=doc.doc_id, rev=doc.rev, content=doc.content)
31 self._conn.putheader('content-length', str(size))
32 self._conn.endheaders()
33 for entry in entries:
34@@ -71,7 +71,7 @@
35 res = simplejson.loads(data[0])
36 for entry in data[1:]:
37 entry = simplejson.loads(entry)
38- doc = Document(entry['id'], entry['rev'], entry['doc'])
39+ doc = Document(entry['id'], entry['rev'], entry['content'])
40 return_doc_cb(doc)
41 data = None
42 return res['new_generation']
43
44=== modified file 'u1db/tests/test_http_app.py'
45--- u1db/tests/test_http_app.py 2011-12-01 14:20:34 +0000
46+++ u1db/tests/test_http_app.py 2011-12-01 21:57:23 +0000
47@@ -551,7 +551,7 @@
48 self.assertEqual(self.db0.get_sync_generation('other-id'), 2)
49
50 def test_sync_exchange_send(self):
51- entry = {'id': 'doc-here', 'rev': 'replica:1', 'doc':
52+ entry = {'id': 'doc-here', 'rev': 'replica:1', 'content':
53 '{"value": "here"}'}
54 args = dict(from_replica_generation=10, last_known_generation=0)
55 body = ("%s\r\n" % simplejson.dumps(args) +
56@@ -581,7 +581,7 @@
57 parts = resp.body.splitlines()
58 self.assertEqual(2, len(parts))
59 self.assertEqual({'new_generation': 1}, simplejson.loads(parts[0]))
60- self.assertEqual({'doc': '{"value": "there"}',
61+ self.assertEqual({'content': '{"value": "there"}',
62 'rev': doc.rev, 'id': doc.doc_id},
63 simplejson.loads(parts[1]))
64

Subscribers

People subscribed via source and target branches