On Tue, Jan 12, 2010 at 8:51 AM, Paul Davis <[email protected]> wrote:
> Matteo,
>
> While you could technically do this, it's quite a violation of the
> properties required for map functions. Identical inputs must lead to
> identical outputs. Otherwise you get all sorts of wonky when the
> queried view changes and there's no way to figure out when
> invalidation should happen.

I think Matteo's not crazy.

This code used to be in couch_httpd_auth before I nuked it:

-        case (catch couch_view:get_map_view(Db, DesignId, ViewName, nil)) of
-        {ok, View, _Group} ->
-            FoldFun = fun({_, Value}, _, {_}) -> {stop, Value} end,
-            {ok, _, {Result}} = couch_view:fold(View, FoldFun, {nil},
-                    [{start_key, {UserName, ?MIN_STR}},{end_key,
{UserName, ?MAX_STR}}]),
-            Result;
-        {not_found, _Reason} ->
-            nil
-            % case (catch couch_view:get_reduce_view(Db, DesignId,
ViewName, nil)) of
-            % {ok, _ReduceView, _Group} ->
-            %     not_implemented;
-            % {not_found, _Reason} ->
-            %     nil
-            % end
-        end



>
> HTH,
> Paul Davis
>
> On Tue, Jan 12, 2010 at 8:18 AM, Matteo Caprari
> <[email protected]> wrote:
>> Hi.
>>
>> In an authorization handler I need to query a view (map only) with a single 
>> key.
>> The map function emits (openid, username) and there is no reduce.
>>
>> I thounk I have to complete the snippet below with couch_view:fold but
>> can't figure out how to generate
>> a valid fold function, let alone one that filters on a given key.
>>
>> find_user_with_openid(Db, OpenId) ->
>>        DesignId = <<"_design/_openid">>,
>>        ViewName = <<"users_by_openids">>
>>        Stale = nil,
>>        {ok, View, Group}  = couch_view:get_map_view(Db, DesignId, ViewName, 
>> nil),
>>
>> Thanks.
>>
>> --
>> :Matteo Caprari
>> [email protected]
>>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Reply via email to