summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-05-20 19:57:37 +0000
committerDamien F. Katz <damien@apache.org>2008-05-20 19:57:37 +0000
commit5da7c1a8ba70f41a8e92cb1efee1f6c6898a2901 (patch)
treee675679054d39391833d0eafeb7a2a5ebac03286 /src
parent2178d96a2f5d2103676d0319c07d1f6bb904b97c (diff)
Fixed design document view definitions to be consistent with temp views. Changed the name of the map(K,V) call in the javascript views to emit(K,V)
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@658405 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_btree.erl7
-rw-r--r--src/couchdb/couch_view.erl16
2 files changed, 9 insertions, 14 deletions
diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl
index 6fd9b0c8..57013ee9 100644
--- a/src/couchdb/couch_btree.erl
+++ b/src/couchdb/couch_btree.erl
@@ -419,7 +419,7 @@ collect_node(Bt, {P, R}, KeyStart, KeyEnd) ->
true -> % got full node, return the already calculated reduction
{[], [{nil, {P, R}}]};
false -> % otherwise return the keyvalues for later reduction
- {KVs2, []}
+ {[assemble(Bt,K,V) || {K,V} <- KVs2], []}
end
end.
@@ -568,9 +568,10 @@ stream_kv_node(Bt, Reds, KVs, StartKey, Dir, Fun, Acc) ->
stream_kv_node2(_Bt, _Reds, _PrevKVs, [], _Dir, _Fun, Acc) ->
{ok, Acc};
stream_kv_node2(Bt, Reds, PrevKVs, [{K,V} | RestKVs], Dir, Fun, Acc) ->
- case Fun(assemble(Bt, K, V), {PrevKVs, Reds}, Acc) of
+ AssembledKV = assemble(Bt, K, V),
+ case Fun(AssembledKV, {PrevKVs, Reds}, Acc) of
{ok, Acc2} ->
- stream_kv_node2(Bt, Reds, [{K,V} | PrevKVs], RestKVs, Dir, Fun, Acc2);
+ stream_kv_node2(Bt, Reds, [AssembledKV | PrevKVs], RestKVs, Dir, Fun, Acc2);
{stop, Acc2} ->
{stop, Acc2}
end.
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl
index 4f6a2f47..b14f4564 100644
--- a/src/couchdb/couch_view.erl
+++ b/src/couchdb/couch_view.erl
@@ -155,32 +155,26 @@ reduce_to_count(Reductions) ->
design_doc_to_view_group(#doc{id=Id,body={obj, Fields}}) ->
Language = proplists:get_value("language", Fields, "javascript"),
{obj, RawViews} = proplists:get_value("views", Fields, {obj, []}),
-
- % extract the map/reduce views from the json fields and into lists
- MapViewsRaw = [{Name, Src, nil} || {Name, Src} <- RawViews, is_list(Src)],
- MapReduceViewsRaw =
- [{Name,
- proplists:get_value("map", MRFuns),
- proplists:get_value("reduce", MRFuns)}
- || {Name, {obj, MRFuns}} <- RawViews],
% add the views to a dictionary object, with the map source as the key
DictBySrc =
lists:foldl(
- fun({Name, MapSrc, RedSrc}, DictBySrcAcc) ->
+ fun({Name, {obj, MRFuns}}, DictBySrcAcc) ->
+ MapSrc = proplists:get_value("map", MRFuns),
+ RedSrc = proplists:get_value("reduce", MRFuns, null),
View =
case dict:find(MapSrc, DictBySrcAcc) of
{ok, View0} -> View0;
error -> #view{def=MapSrc} % create new view object
end,
View2 =
- if RedSrc == nil ->
+ if RedSrc == null ->
View#view{map_names=[Name|View#view.map_names]};
true ->
View#view{reduce_funs=[{Name,RedSrc}|View#view.reduce_funs]}
end,
dict:store(MapSrc, View2, DictBySrcAcc)
- end, dict:new(), MapViewsRaw ++ MapReduceViewsRaw),
+ end, dict:new(), RawViews),
% number the views
{Views, _N} = lists:mapfoldl(
fun({_Src, View}, N) ->