-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for bulk get with Accept:"multipart/mixed" or "multipart/related" #1195
Conversation
this is pretty cool. Before I do a more thorough review, I’m wondering why you didn’t opt to re-use |
Hi @janl , thanks for a good question. |
Yeah, I really don't feel comfortable having two multipart implementations in CouchDB. We already don't like the one we have. ;) |
Hi @janl , thank you for your advice to stick to the |
Hi, |
@AlexanderKaraberov Sorry about not being able to get this included in 2.2.0, but it might land for 2.2.1 or 2.3.0. @mikerhodes @davisp another one that could use your reviews. Would also love any comments from the PouchDB crew e.g. @garrensmith @daleharvey |
@AlexanderKaraberov Can you resolve the conflicts on this PR please? @garrensmith do you think you could review this PR please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thanks for contributing and sorry for taking so long to review. Added a few comments. There are some functional changes and some style comments.
Don't forget to rebase on master and squash the commits. There is a merge conflict, where we updated options to take user's context.
Thank you!
Hello @nickva |
Looks much better. Nice work cleaning it up. I see eunit test failures locally and in Travis. Not sure exactly why, maybe because of the name change of the function or maybe something on master changed? Also see a minor comment about simplifying meck unloading. |
Valid point. |
@nickva I checked Travis logs and seemingly only one job
|
Ah it's probably flaky, I'll try to restart it |
@nickva Thanks! Indeed it was some intermittent failure. All is good now. Let me know if I need to address something else before this can be merged into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also squash the commits if you fix it up and rebase again. There were some recent changes in the replicator but shouldn't affect this PR.
Thank you again for you contribution.
+1 Thank you for your contribution and for your patience when reviewing the PR Let's do a final ping on this to other developers who looked at this before @garrensmith @rnewson @janl @wohali |
Added a rebased on master PR #1195 Not sure why "update branch" button in GH doesn't allow rebasing on master :-) |
Thank you again for you contribution. I rebased and merged your PR. Please make a documentation PR to go along with it. |
@nickva Thanks! Sure, I shall allocate some time in order to update related documentation and submit a PR for it. |
@AlexanderKaraberov Thanks, please be advised I am moving swiftly into 2.3.0 release time, so a little urgency would be much appreciated. :) |
Overview
CouchDB currently has support for
_bulk_get
requests which are intended to improve performance of client pull replications, by allowing the client to request multiple documents in one request. But current implementation has some limitations namely: attachment bodies can only be encoded inline (base64) not as MIME multipart bodies. Another issue which is much more important I believe: current _bulk_get implementation in CouchDB is not compatible with the Couchbase Lite 1.4.x for iOS and Android which powers plenty of CouchDB mobile clients (in our company as well) as a replication and persistence layer. This is because CBL'sBulkDownloader
accepts multipart/related content type and notapplication/json
. I understand that probably this was done to make life easier for web clients and in-browser DBs such as PouchDB or whatnot, but still this functionality might be extended to provide even more use cases for CouchDB’s_bulk_get
. In order to sum up I believe that this is a must-have feature.This PR adds support for
multipart/related
/multipart/mixed
bulk get response which is compatible with Couchbase Lite and Sync Gateway implementations. At first I implemented this functionality in our own CouchDB 2.x fork which we run in production, because this was very crucial for us, as I mentioned before, but then we realised that it would be great to contribute this to the upstream CouchDB as well.Logic and implementation is pretty straightforward and compact: depending on the
case MochiReq:accepts_content_type("multipart/mixed" or "multipart/related")
I pick either a default CouchDB's_bulk_get
implementation or a multipart one which is based on existingcouch_doc:doc_to_multi_part_stream()
andcouch_httpd_db:encode_multipart_stream()
functionality.We’ve already tested this with some of our production CouchDB databases and speedup was very perceptible. I think this feature will be very useful because there may be a lot of Couchbase Lite <-> CouchDB users who can't benefit from the
_bulk_get
because ofapplication/json
-only response. Moreover this is a completely additive change which doesn't break or change existing functionality. Test suite is completely based on thechttpd_db_bulk_get_test
I've just changed test fixture and some helpers a little bit.Testing recommendations
For testing create a
db1
, put some docs there:Also add attachments for some of the docs (.png images or whatnot).
Add this request body to
bulkGetBody.txt
file (revisions have to be the same as in the corresponding documents):After this you can execute this curl command:
Then in the
response.txt
you can observe this:This format is completely compatible with Couchbase Lite and also Sync Gateway implementation.
For testing you can also use Couchbase Lite database. In order to do this just set _canBulkGet variable to
YES
and then replicate db1 to iOS mobile device.I checked
Documentation reflects the changes
checkbox because I described the change quite meticulously and if this PR will be merged I would be delighted to update CouchDB docs as well. By the way I wasn't able to find a description for current_bulk_doc
request in the docs either so I can contribute to both.Checklist