couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r987563 - in /couchdb/branches/new_replicator/src/couchdb: couch_api_wrap.erl couch_api_wrap_httpc.erl
Date Fri, 20 Aug 2010 16:23:39 GMT
Author: fdmanana
Date: Fri Aug 20 16:23:39 2010
New Revision: 987563

URL: http://svn.apache.org/viewvc?rev=987563&view=rev
Log:
Import functions from couch_util that are used very often to reduce code size (specially for
some incoming changes).

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl?rev=987563&r1=987562&r2=987563&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Fri Aug 20 16:23:39 2010
@@ -51,6 +51,12 @@
     send_req/3
     ]).
 
+-import(couch_util, [
+    url_encode/1,
+    get_value/2,
+    get_value/3
+    ]).
+
 
 db_open(Db, Options) ->
     db_open(Db, Options, false).
@@ -112,7 +118,7 @@ ensure_full_commit(#httpdb{} = Db) ->
         Db,
         [{method, post}, {path, "_ensure_full_commit"}, {direct, true}],
         fun(201, _, {Props}) ->
-            {ok, couch_util:get_value(<<"instance_start_time">>, Props)}
+            {ok, get_value(<<"instance_start_time">>, Props)}
         end);
 ensure_full_commit(Db) ->
     couch_db:ensure_full_commit(Db).
@@ -127,10 +133,10 @@ get_missing_revs(#httpdb{} = Db, IdRevs)
         fun(200, _, {Props}) ->
             ConvertToNativeFun = fun({Id, {Result}}) ->
                 MissingRevs = couch_doc:parse_revs(
-                    couch_util:get_value(<<"missing">>, Result)
+                    get_value(<<"missing">>, Result)
                 ),
                 PossibleAncestors = couch_doc:parse_revs(
-                    couch_util:get_value(<<"possible_ancestors">>, Result, [])
+                    get_value(<<"possible_ancestors">>, Result, [])
                 ),
                 {Id, MissingRevs, PossibleAncestors}
             end,
@@ -150,9 +156,9 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Re
     ],
     IdEncoded = case Id of
     <<"_design/", RestId/binary>> ->
-        "_design/" ++ couch_util:url_encode(RestId);
+        "_design/" ++ url_encode(RestId);
     _ ->
-        couch_util:url_encode(Id)
+        url_encode(Id)
     end,
     Streamer = spawn_link(fun() ->
             send_req(
@@ -161,9 +167,8 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Re
                     {ibrowse_options, [{stream_to, {self(), once}}]},
                     {headers, [{"accept", "multipart/mixed"}]}],
                 fun(200, Headers, StreamDataFun) ->
-                    CType = couch_util:get_value("Content-Type", Headers),
                     couch_httpd:parse_multipart_request(
-                        CType,
+                        get_value("Content-Type", Headers),
                         StreamDataFun,
                         fun(Ev) -> mp_parse_mixed(Ev) end)
                 end),
@@ -185,9 +190,9 @@ open_doc(#httpdb{} = HttpDb, Id, Options
     ],
     IdEncoded = case Id of
     <<"_design/", RestId/binary>> ->
-        "_design/" ++ couch_util:url_encode(RestId);
+        "_design/" ++ url_encode(RestId);
     _ ->
-        couch_util:url_encode(Id)
+        url_encode(Id)
     end,
     Self = self(),
     Streamer = spawn_link(fun() ->
@@ -197,7 +202,7 @@ open_doc(#httpdb{} = HttpDb, Id, Options
                     {path, IdEncoded}, {qs, QArgs}, {direct, true},
                     {ibrowse_options, [{stream_to, {self(), once}}]}],
                 fun(Code, Headers, StreamDataFun) ->
-                    CType = couch_util:get_value("Content-Type", Headers),
+                    CType = get_value("Content-Type", Headers),
                     Self ! {self(), CType},
                     case CType of
                     "application/json" ->
@@ -279,10 +284,10 @@ update_doc(#httpdb{} = HttpDb, #doc{id =
     end,
     send_req(
         HttpDb,
-        [{method, put}, {path, couch_util:url_encode(DocId)}, {direct, true},
+        [{method, put}, {path, url_encode(DocId)}, {direct, true},
             {qs, QArgs}, {headers, Headers}, {body, {SendFun, Len}}],
         fun(Code, _, {Props}) when Code =:= 200 orelse Code =:= 201 ->
-            {ok, couch_doc:parse_rev(couch_util:get_value(<<"rev">>, Props))}
+            {ok, couch_doc:parse_rev(get_value(<<"rev">>, Props))}
         end);
 update_doc(Db, Doc, Options, Type) ->
     couch_db:update_doc(Db, Doc, Options, Type).
@@ -305,8 +310,8 @@ changes_since(Db, Style, StartSeq, UserF
     Args = #changes_args{
         style = Style,
         since = StartSeq,
-        filter = ?b2l(couch_util:get_value(filter, Options, <<>>)),
-        feed = case couch_util:get_value(continuous, Options, false) of
+        filter = ?b2l(get_value(filter, Options, <<>>)),
+        feed = case get_value(continuous, Options, false) of
             true ->
                 "continuous";
             false ->
@@ -314,7 +319,7 @@ changes_since(Db, Style, StartSeq, UserF
         end,
         timeout = infinity
     },
-    QueryParams = couch_util:get_value(query_params, Options, {[]}),
+    QueryParams = get_value(query_params, Options, {[]}),
     Req = changes_json_req(Db, Args#changes_args.filter, QueryParams),
     ChangesFeedFun = couch_changes:handle_changes(Args, {json_req, Req}, Db),
     ChangesFeedFun(fun({change, Change, _}, _) ->
@@ -327,11 +332,11 @@ changes_since(Db, Style, StartSeq, UserF
 % internal functions
 
 changes_q_args(BaseQS, Options) ->
-    case couch_util:get_value(filter, Options) of
+    case get_value(filter, Options) of
     undefined ->
         BaseQS;
     FilterName ->
-        {Params} = couch_util:get_value(query_params, Options, {[]}),
+        {Params} = get_value(query_params, Options, {[]}),
         [{"filter", ?b2l(FilterName)} | lists:foldl(
             fun({K, V}, QSAcc) ->
                 Ks = couch_util:to_list(K),
@@ -383,7 +388,7 @@ receive_docs(Streamer, UserFun, UserAcc)
     Streamer ! {get_headers, self()},
     receive
     {headers, Headers} ->    
-        case couch_util:get_value("content-type", Headers) of
+        case get_value("content-type", Headers) of
         {"multipart/related", _} = ContentType ->
             case couch_doc:doc_from_multi_part_stream(ContentType, 
                 fun() -> receive_doc_data(Streamer) end) of
@@ -398,7 +403,7 @@ receive_docs(Streamer, UserFun, UserAcc)
             receive_docs(Streamer, UserFun, UserAcc2);
         {"application/json", [{"error","true"}]} ->
             {ErrorProps} = ?JSON_DECODE(receive_all(Streamer, [])),
-            Rev = couch_util:get_value(<<"missing">>, ErrorProps),
+            Rev = get_value(<<"missing">>, ErrorProps),
             Result = {{not_found, missing}, couch_doc:parse_rev(Rev)},
             UserAcc2 = UserFun(Result, UserAcc),
             receive_docs(Streamer, UserFun, UserAcc2)
@@ -482,14 +487,14 @@ changes_ev_done() ->
     fun(_Ev) -> changes_ev_done() end.
 
 json_to_doc_info({Props}) ->
-    Id = couch_util:get_value(<<"id">>, Props),
-    Seq = couch_util:get_value(<<"seq">>, Props),
-    Changes = couch_util:get_value(<<"changes">>, Props),
-
     RevsInfo = lists:map(
         fun({Change}) ->
-            Rev = couch_doc:parse_rev(couch_util:get_value(<<"rev">>, Change)),
-            Del = (true =:= couch_util:get_value(<<"deleted">>, Change)),
+            Rev = couch_doc:parse_rev(get_value(<<"rev">>, Change)),
+            Del = (true =:= get_value(<<"deleted">>, Change)),
             #rev_info{rev=Rev, deleted=Del}
-        end, Changes),
-    #doc_info{id=Id, high_seq=Seq, revs=RevsInfo}.
+        end, get_value(<<"changes">>, Props)),
+    #doc_info{
+        id = get_value(<<"id">>, Props),
+        high_seq = get_value(<<"seq">>, Props),
+        revs = RevsInfo
+    }.

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl?rev=987563&r1=987562&r2=987563&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl Fri Aug 20 16:23:39
2010
@@ -19,6 +19,11 @@
 -export([httpdb_setup/1]).
 -export([send_req/3]).
 
+-import(couch_util, [
+    get_value/2,
+    get_value/3
+    ]).
+
 
 httpdb_setup(#httpdb{url = Url} = Db) ->
     #url{host = Host, port = Port} = ibrowse_lib:parse_url(Url),
@@ -36,16 +41,16 @@ max_sessions() ->
 
 send_req(HttpDb, Params, Callback) ->
     #httpdb{headers = BaseHeaders, oauth = OAuth} = HttpDb,
-    Method = couch_util:get_value(method, Params, get),
-    Headers = couch_util:get_value(headers, Params, []),
-    Body = couch_util:get_value(body, Params, []),
+    Method = get_value(method, Params, get),
+    Headers = get_value(headers, Params, []),
+    Body = get_value(body, Params, []),
     IbrowseOptions = [
         {response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout}
-        | couch_util:get_value(ibrowse_options, Params, [])
+        | get_value(ibrowse_options, Params, [])
     ],
     Url = full_url(HttpDb, Params),
     Headers2 = oauth_header(Url, [], Method, OAuth) ++ BaseHeaders ++ Headers,
-    {Response, Worker} = case couch_util:get_value(direct, Params, false) of
+    {Response, Worker} = case get_value(direct, Params, false) of
     false ->
         Resp = ibrowse:send_req(
             Url, Headers2, Method, Body, IbrowseOptions, infinity),
@@ -120,8 +125,7 @@ report_error(Worker, #httpdb{timeout = T
     report_error(Worker, HttpDb, Params, {timeout, Timeout});
 
 report_error(Worker, HttpDb, Params, Error) ->
-    Method = string:to_upper(
-        atom_to_list(couch_util:get_value(method, Params, get))),
+    Method = string:to_upper(atom_to_list(get_value(method, Params, get))),
     Url = strip_creds(full_url(HttpDb, Params)),
     do_report_error(Url, Method, Error),
     stop_worker(Worker),
@@ -153,8 +157,8 @@ stream_data_self(HttpDb, Params, Worker,
 
 
 full_url(#httpdb{url = BaseUrl}, Params) ->
-    Path = couch_util:get_value(path, Params, []),
-    QueryArgs = couch_util:get_value(qs, Params, []),
+    Path = get_value(path, Params, []),
+    QueryArgs = get_value(qs, Params, []),
     BaseUrl ++ Path ++ query_args_to_string(QueryArgs, []).
 
 



Mime
View raw message