summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-08 11:39:13 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-06-08 11:39:13 -0400
commit4e0c97bf3587e9d0e330494f0d06194c0c4bfa17 (patch)
treef5a4f7e5d21f24f94054770dfbe9ff5214c7aea1
parent42a45f2a77a125f8c0f5be99edd574fbe391f1ee (diff)
allow for unsorted results in map queries, BugzID 10073
-rw-r--r--include/fabric.hrl1
-rw-r--r--src/fabric_view_map.erl12
2 files changed, 13 insertions, 0 deletions
diff --git a/include/fabric.hrl b/include/fabric.hrl
index f4665ca8..7fdb5bed 100644
--- a/include/fabric.hrl
+++ b/include/fabric.hrl
@@ -26,6 +26,7 @@
os_proc,
reducer,
lang,
+ sorted,
user_acc
}).
diff --git a/src/fabric_view_map.erl b/src/fabric_view_map.erl
index 8316979f..b20a0f39 100644
--- a/src/fabric_view_map.erl
+++ b/src/fabric_view_map.erl
@@ -21,6 +21,7 @@ go(DbName, {GroupId, View}, Args, Callback, Acc0) ->
limit = Limit,
stop_fun = stop_fun(Args),
keys = fabric_view:keydict(Keys),
+ sorted = Args#view_query_args.sorted,
user_acc = Acc0
},
try fabric_util:receive_loop(Workers, #shard.ref, fun handle_message/3,
@@ -88,6 +89,17 @@ handle_message({total_and_offset, Tot, Off}, {Worker, From}, State) ->
end
end;
+handle_message(#view_row{}, {_, _}, #collector{limit=0} = State) ->
+ #collector{callback=Callback} = State,
+ {_, Acc} = Callback(complete, State#collector.user_acc),
+ {stop, State#collector{user_acc=Acc}};
+
+handle_message(#view_row{} = Row, {_,From}, #collector{sorted=false} = St) ->
+ #collector{callback=Callback, user_acc=AccIn, limit=Limit} = St,
+ {Go, Acc} = Callback(fabric_view:transform_row(Row), AccIn),
+ gen_server:reply(From, ok),
+ {Go, St#collector{user_acc=Acc, limit=Limit-1}};
+
handle_message(#view_row{} = Row, {Worker, From}, State) ->
#collector{
query_args = #view_query_args{direction=Dir},