Merge lp:~sil/u1db/http-all-docs into lp:u1db

Proposed by Stuart Langridge
Status: Rejected
Rejected by: Samuele Pedroni
Proposed branch: lp:~sil/u1db/http-all-docs
Merge into: lp:u1db
Diff against target: 85 lines (+64/-0)
2 files modified
u1db/remote/http_app.py (+23/-0)
u1db/tests/test_http_app.py (+41/-0)
To merge this branch: bzr merge lp:~sil/u1db/http-all-docs
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Review via email: mp+122637@code.launchpad.net

Description of the change

Add /docs/all-ids HTTP endpoint which returns a list of all docids (filtered by include_deleted)

To post a comment you must log in.
lp:~sil/u1db/http-all-docs updated
395. By Stuart Langridge

declare only the correct parameter in the http decorator

Revision history for this message
Eric Casteleijn (thisfred) wrote :

I would think we'd want a non-http version of this as well, which the http version can then call? That way it can be optimized in backends that have ways of getting the ids directly.

Revision history for this message
Stuart Langridge (sil) wrote :

but then it has to be implemented by backends rather than building on the existing backend API.

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Well yes, but they can always implement it using the 3 lines shown here. For python, we could add that to the reference implementation even, and backends could override it. I am not 100% sure about this, though, so maybe adding the http implementation only for now is the way to go, since we know we need that, and for the general API we don't yet.

Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve
Revision history for this message
Samuele Pedroni (pedronis) wrote :

superseded

Unmerged revisions

395. By Stuart Langridge

declare only the correct parameter in the http decorator

394. By Stuart Langridge

Add /docs/all-ids HTTP endpoint which returns a list of all docids (filtered by include_deleted)

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 2012-08-20 21:29:46 +0000
3+++ u1db/remote/http_app.py 2012-09-04 09:29:22 +0000
4@@ -244,6 +244,29 @@
5
6
7 @url_to_resource.register
8+class AllDocsIdsResource(object):
9+ """All document IDs resource."""
10+
11+ url_pattern = "/{dbname}/docs/all-ids"
12+
13+ def __init__(self, dbname, state, responder):
14+ self.responder = responder
15+ self.db = state.open_database(dbname)
16+
17+ @http_method(include_deleted=parse_bool)
18+ def get(self, include_deleted=False):
19+ gen, docs = self.db.get_all_docs(include_deleted=include_deleted)
20+ self.responder.content_type = 'application/json'
21+ self.responder.start_response(200)
22+ self.responder.start_stream(),
23+ for doc in docs:
24+ entry = doc.doc_id
25+ self.responder.stream_entry(entry)
26+ self.responder.end_stream()
27+ self.responder.finish_response()
28+
29+
30+@url_to_resource.register
31 class DocsResource(object):
32 """Documents resource."""
33
34
35=== modified file 'u1db/tests/test_http_app.py'
36--- u1db/tests/test_http_app.py 2012-08-20 21:29:46 +0000
37+++ u1db/tests/test_http_app.py 2012-09-04 09:29:22 +0000
38@@ -738,6 +738,47 @@
39 "has_conflicts": False}]
40 self.assertEqual(expected, json.loads(resp.body))
41
42+ def test_get_docs_all(self):
43+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
44+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
45+ resp = self.app.get('/db0/docs/all-ids')
46+ self.assertEqual(200, resp.status)
47+ self.assertEqual(
48+ 'application/json', resp.header('content-type'))
49+ expected = sorted([doc1.doc_id, doc2.doc_id])
50+ self.assertEqual(expected, sorted(json.loads(resp.body)))
51+
52+ def test_get_docs_all_empty(self):
53+ resp = self.app.get('/db0/docs/all-ids')
54+ self.assertEqual(200, resp.status)
55+ self.assertEqual(
56+ 'application/json', resp.header('content-type'))
57+ self.assertEqual([], json.loads(resp.body))
58+
59+ def test_get_docs_all_exclude_deleted(self):
60+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
61+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
62+ doc3 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc3')
63+ self.db0.delete_doc(doc1)
64+ resp = self.app.get('/db0/docs/all-ids')
65+ self.assertEqual(200, resp.status)
66+ self.assertEqual(
67+ 'application/json', resp.header('content-type'))
68+ expected = sorted([doc2.doc_id, doc3.doc_id])
69+ self.assertEqual(expected, sorted(json.loads(resp.body)))
70+
71+ def test_get_docs_all_include_deleted(self):
72+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
73+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
74+ doc3 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc3')
75+ self.db0.delete_doc(doc1)
76+ resp = self.app.get('/db0/docs/all-ids?include_deleted=true')
77+ self.assertEqual(200, resp.status)
78+ self.assertEqual(
79+ 'application/json', resp.header('content-type'))
80+ expected = sorted([doc1.doc_id, doc2.doc_id, doc3.doc_id])
81+ self.assertEqual(expected, sorted(json.loads(resp.body)))
82+
83 def test_get_docs_include_deleted(self):
84 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
85 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')

Subscribers

People subscribed via source and target branches