Permalink
Browse files

RCBC-89 Fetch documents using binary protocol by default

Change-Id: I50104ffbd40872c23031423fe372649b6d6a8f67
Reviewed-on: http://review.couchbase.org/22451
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
avsej committed Nov 12, 2012
1 parent 2f6c22e commit c2a13ed6af9fd448a03d926c71c6be12b030e2e4
Showing with 29 additions and 2 deletions.
  1. +29 −2 lib/couchbase/view.rb
View
@@ -142,8 +142,12 @@ def on_error(&callback)
# the document and store them in {ViewRow#meta} hash.
#
# @param [Hash] params parameters for Couchbase query.
- # @option params [true, false] :include_docs (false) Include the full
- # content of the documents in the return.
+ # @option params [true, false, :http] :include_docs (false) Include the
+ # full content of the documents in the return. This option can force
+ # document fetching in two different ways: embedding documents in HTTP
+ # stream or query them using binary protocol. In first case you should
+ # pass symbol +:http+ as an argument, for second case pass any ruby
+ # truth value (like +true+).
# @option params [true, false] :descending (false) Return the documents
# in descending by key order
# @option params [String, Fixnum, Hash, Array] :key Return only
@@ -236,6 +240,18 @@ def fetch(params = {})
body = MultiJson.dump(body) unless body.is_a?(String)
options.update(:body => body, :method => params.delete(:method) || :post)
end
+ use_bin_protocol = false
+ case params[:include_docs]
+ when :http
+ # retrieve documents embedded into view response
+ params[:include_docs] = true
+ when nil, false
+ params.delete(:include_docs)
+ else
+ # retrieve documents using binary protocol
+ params.delete(:include_docs)
+ use_bin_protocol = true
+ end
path = Utils.build_query(@endpoint, params)
request = @bucket.make_http_request(path, options)
res = []
@@ -260,6 +276,17 @@ def fetch(params = {})
raise Error::View.new(from, reason)
end
else
+ if use_bin_protocol
+ val, flags, cas = @bucket.get(obj['id'], :extended => true)
+ obj['doc'] = {
+ 'value' => val,
+ 'meta' => {
+ 'id' => obj['id'],
+ 'flags' => flags,
+ 'cas' => cas
+ }
+ }
+ end
if block_given?
yield @wrapper_class.wrap(@bucket, obj)
else

0 comments on commit c2a13ed

Please sign in to comment.