couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject [1/2] couchdb-mango git commit: Return fields provided by user only
Date Tue, 08 Dec 2015 21:11:28 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/2913-port-missed-commits [created] db3116c48


Return fields provided by user only

When the user specifies Fields with his or her selector, filter out
fields that are not in the Fields list.

BugzId: 43810


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/f1f816b2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/f1f816b2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/f1f816b2

Branch: refs/heads/2913-port-missed-commits
Commit: f1f816b21839a7df49f527f887f65afd88bc7119
Parents: a02f610
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Wed Jan 28 10:26:33 2015 -0800
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Tue Dec 8 13:01:37 2015 -0800

----------------------------------------------------------------------
 src/mango_cursor_text.erl | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f1f816b2/src/mango_cursor_text.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor_text.erl b/src/mango_cursor_text.erl
index 847b04c..9f2beeb 100644
--- a/src/mango_cursor_text.erl
+++ b/src/mango_cursor_text.erl
@@ -35,7 +35,8 @@
     limit,
     skip,
     user_fun,
-    user_acc
+    user_acc,
+    fields
 }).
 
 
@@ -53,7 +54,6 @@ create(Db, Indexes, Selector, Opts0) ->
     Limit = erlang:min(DreyfusLimit, couch_util:get_value(limit, Opts, 50)),
     Skip = couch_util:get_value(skip, Opts, 0),
     Fields = couch_util:get_value(fields, Opts, all_fields),
-
     {ok, #cursor{
         db = Db,
         index = Index,
@@ -101,7 +101,8 @@ execute(Cursor, UserFun, UserAcc) ->
         skip = Skip,
         query_args = QueryArgs,
         user_fun = UserFun,
-        user_acc = UserAcc
+        user_acc = UserAcc,
+        fields = Cursor#cursor.fields
     },
     try
         execute(CAcc)
@@ -184,11 +185,12 @@ handle_hit(CAcc0, Sort, Doc) ->
 
 
 apply_user_fun(CAcc, Doc) ->
+    FinalDoc = mango_fields:extract(Doc, CAcc#cacc.fields),
     #cacc{
         user_fun = UserFun,
         user_acc = UserAcc
     } = CAcc,
-    case UserFun({row, Doc}, UserAcc) of
+    case UserFun({row, FinalDoc}, UserAcc) of
         {ok, NewUserAcc} ->
             CAcc#cacc{user_acc = NewUserAcc};
         {stop, NewUserAcc} ->


Mime
View raw message