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
=== modified file 'u1db/remote/http_app.py'
--- u1db/remote/http_app.py 2012-08-20 21:29:46 +0000
+++ u1db/remote/http_app.py 2012-09-04 09:29:22 +0000
@@ -244,6 +244,29 @@
244244
245245
246@url_to_resource.register246@url_to_resource.register
247class AllDocsIdsResource(object):
248 """All document IDs resource."""
249
250 url_pattern = "/{dbname}/docs/all-ids"
251
252 def __init__(self, dbname, state, responder):
253 self.responder = responder
254 self.db = state.open_database(dbname)
255
256 @http_method(include_deleted=parse_bool)
257 def get(self, include_deleted=False):
258 gen, docs = self.db.get_all_docs(include_deleted=include_deleted)
259 self.responder.content_type = 'application/json'
260 self.responder.start_response(200)
261 self.responder.start_stream(),
262 for doc in docs:
263 entry = doc.doc_id
264 self.responder.stream_entry(entry)
265 self.responder.end_stream()
266 self.responder.finish_response()
267
268
269@url_to_resource.register
247class DocsResource(object):270class DocsResource(object):
248 """Documents resource."""271 """Documents resource."""
249272
250273
=== modified file 'u1db/tests/test_http_app.py'
--- u1db/tests/test_http_app.py 2012-08-20 21:29:46 +0000
+++ u1db/tests/test_http_app.py 2012-09-04 09:29:22 +0000
@@ -738,6 +738,47 @@
738 "has_conflicts": False}]738 "has_conflicts": False}]
739 self.assertEqual(expected, json.loads(resp.body))739 self.assertEqual(expected, json.loads(resp.body))
740740
741 def test_get_docs_all(self):
742 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
743 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
744 resp = self.app.get('/db0/docs/all-ids')
745 self.assertEqual(200, resp.status)
746 self.assertEqual(
747 'application/json', resp.header('content-type'))
748 expected = sorted([doc1.doc_id, doc2.doc_id])
749 self.assertEqual(expected, sorted(json.loads(resp.body)))
750
751 def test_get_docs_all_empty(self):
752 resp = self.app.get('/db0/docs/all-ids')
753 self.assertEqual(200, resp.status)
754 self.assertEqual(
755 'application/json', resp.header('content-type'))
756 self.assertEqual([], json.loads(resp.body))
757
758 def test_get_docs_all_exclude_deleted(self):
759 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
760 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
761 doc3 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc3')
762 self.db0.delete_doc(doc1)
763 resp = self.app.get('/db0/docs/all-ids')
764 self.assertEqual(200, resp.status)
765 self.assertEqual(
766 'application/json', resp.header('content-type'))
767 expected = sorted([doc2.doc_id, doc3.doc_id])
768 self.assertEqual(expected, sorted(json.loads(resp.body)))
769
770 def test_get_docs_all_include_deleted(self):
771 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
772 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
773 doc3 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc3')
774 self.db0.delete_doc(doc1)
775 resp = self.app.get('/db0/docs/all-ids?include_deleted=true')
776 self.assertEqual(200, resp.status)
777 self.assertEqual(
778 'application/json', resp.header('content-type'))
779 expected = sorted([doc1.doc_id, doc2.doc_id, doc3.doc_id])
780 self.assertEqual(expected, sorted(json.loads(resp.body)))
781
741 def test_get_docs_include_deleted(self):782 def test_get_docs_include_deleted(self):
742 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')783 doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
743 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')784 doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')

Subscribers

People subscribed via source and target branches