1313-module (couch_access_native_proc ).
1414-behavior (gen_server ).
1515
16-
1716-export ([
1817 start_link /0 ,
1918 set_timeout /2 ,
2928 code_change /3
3029]).
3130
32-
3331-record (st , {
3432 indexes = [],
35- timeout = 5000 % TODO: make configurable
33+ % TODO: make configurable
34+ timeout = 5000
3635}).
3736
3837start_link () ->
3938 gen_server :start_link (? MODULE , [], []).
4039
41-
4240set_timeout (Pid , TimeOut ) when is_integer (TimeOut ), TimeOut > 0 ->
4341 gen_server :call (Pid , {set_timeout , TimeOut }).
4442
45-
4643prompt (Pid , Data ) ->
4744 gen_server :call (Pid , {prompt , Data }).
4845
49-
5046init (_ ) ->
5147 {ok , # st {}}.
5248
53-
5449terminate (_Reason , _St ) ->
5550 ok .
5651
57-
5852handle_call ({set_timeout , TimeOut }, _From , St ) ->
59- {reply , ok , St # st {timeout = TimeOut }};
60-
53+ {reply , ok , St # st {timeout = TimeOut }};
6154handle_call ({prompt , [<<" reset" >>]}, _From , St ) ->
62- {reply , true , St # st {indexes = []}};
63-
55+ {reply , true , St # st {indexes = []}};
6456handle_call ({prompt , [<<" reset" >>, _QueryConfig ]}, _From , St ) ->
65- {reply , true , St # st {indexes = []}};
66-
57+ {reply , true , St # st {indexes = []}};
6758handle_call ({prompt , [<<" add_fun" >>, IndexInfo ]}, _From , St ) ->
6859 {reply , true , St };
69-
7060handle_call ({prompt , [<<" map_doc" >>, Doc ]}, _From , St ) ->
7161 {reply , map_doc (St , mango_json :to_binary (Doc )), St };
72-
7362handle_call ({prompt , [<<" reduce" >>, _ , _ ]}, _From , St ) ->
7463 {reply , null , St };
75-
7664handle_call ({prompt , [<<" rereduce" >>, _ , _ ]}, _From , St ) ->
7765 {reply , null , St };
78-
7966handle_call ({prompt , [<<" index_doc" >>, Doc ]}, _From , St ) ->
8067 {reply , [[]], St };
81-
8268handle_call (Msg , _From , St ) ->
8369 {stop , {invalid_call , Msg }, {invalid_call , Msg }, St }.
8470
8571handle_cast (garbage_collect , St ) ->
8672 erlang :garbage_collect (),
8773 {noreply , St };
88-
8974handle_cast (Msg , St ) ->
9075 {stop , {invalid_cast , Msg }, St }.
9176
92-
9377handle_info (Msg , St ) ->
9478 {stop , {invalid_info , Msg }, St }.
9579
96-
9780code_change (_OldVsn , St , _Extra ) ->
9881 {ok , St }.
9982
@@ -115,29 +98,42 @@ code_change(_OldVsn, St, _Extra) ->
11598map_doc (_St , {Doc }) ->
11699 case couch_util :get_value (<<" _access" >>, Doc ) of
117100 undefined ->
118- [[],[]]; % do not index this doc
101+ % do not index this doc
102+ [[], []];
119103 Access when is_list (Access ) ->
120104 Id = couch_util :get_value (<<" _id" >>, Doc ),
121105 Rev = couch_util :get_value (<<" _rev" >>, Doc ),
122106 Seq = couch_util :get_value (<<" _seq" >>, Doc ),
123107 Deleted = couch_util :get_value (<<" _deleted" >>, Doc , false ),
124108 BodySp = couch_util :get_value (<<" _body_sp" >>, Doc ),
125109 % by-access-id
126- ById = case Deleted of
127- false ->
128- lists :map (fun (UserOrRole ) -> [
129- [[UserOrRole , Id ], Rev ]
130- ] end , Access );
131- _True -> [[]]
132- end ,
110+ ById =
111+ case Deleted of
112+ false ->
113+ lists :map (
114+ fun (UserOrRole ) ->
115+ [
116+ [[UserOrRole , Id ], Rev ]
117+ ]
118+ end ,
119+ Access
120+ );
121+ _True ->
122+ [[]]
123+ end ,
133124
134125 % by-access-seq
135- BySeq = lists :map (fun (UserOrRole ) -> [
136- [[UserOrRole , Seq ], [{rev , Rev }, {deleted , Deleted }, {body_sp , BodySp }]]
137- ] end , Access ),
126+ BySeq = lists :map (
127+ fun (UserOrRole ) ->
128+ [
129+ [[UserOrRole , Seq ], [{rev , Rev }, {deleted , Deleted }, {body_sp , BodySp }]]
130+ ]
131+ end ,
132+ Access
133+ ),
138134 ById ++ BySeq ;
139135 Else ->
140136 % TODO: no comprende: should not be needed once we implement
141137 % _access field validation
142- [[],[]]
138+ [[], []]
143139 end .
0 commit comments