couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [06/25] couch commit: updated refs/heads/master to 92598cd
Date Thu, 15 Oct 2015 16:35:40 GMT
Extract parse_multipart_stream from doc_from_multi_part_stream


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/51f3aa51
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/51f3aa51
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/51f3aa51

Branch: refs/heads/master
Commit: 51f3aa510d338cda4a3d2b3a8d86e37eb0494d71
Parents: f265acf
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Nov 27 15:32:40 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed May 6 06:55:58 2015 -0700

----------------------------------------------------------------------
 src/couch_httpd_multipart.erl | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/51f3aa51/src/couch_httpd_multipart.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_multipart.erl b/src/couch_httpd_multipart.erl
index 0d3131e..5ea8327 100644
--- a/src/couch_httpd_multipart.erl
+++ b/src/couch_httpd_multipart.erl
@@ -11,6 +11,24 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
 
 
 doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
+    case parse_multipart_stream(ContentType, DataFun, Ref) of
+    {{started_open_doc_revs, NewRef}, Parser, _ParserRef} ->
+        couch_doc:restart_open_doc_revs(Parser, Ref, NewRef);
+    {{doc_bytes, Ref, DocBytes}, Parser, ParserRef} ->
+        Doc = couch_doc:from_json_obj(?JSON_DECODE(DocBytes)),
+        % we'll send the Parser process ID to the remote nodes so they can
+        % retrieve their own copies of the attachment data
+        WithParser = fun(follows) -> {follows, Parser, Ref}; (D) -> D end,
+        Atts = [couch_att:transform(data, WithParser, A) || A <- Doc#doc.atts],
+        WaitFun = fun() ->
+            receive {'DOWN', ParserRef, _, _, _} -> ok end,
+            erlang:put(mochiweb_request_recv, true)
+        end,
+        {ok, Doc#doc{atts=Atts}, WaitFun, Parser};
+    ok -> ok
+    end.
+
+parse_multipart_stream(ContentType, DataFun, Ref) ->
     Parent = self(),
     NumMpWriters = num_mp_writers(),
     {Parser, ParserRef} = spawn_monitor(fun() ->
@@ -25,18 +43,10 @@ doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
     Parser ! {get_doc_bytes, Ref, self()},
     receive
     {started_open_doc_revs, NewRef} ->
-        couch_doc:restart_open_doc_revs(Parser, Ref, NewRef);
-    {doc_bytes, Ref, DocBytes} ->
-        Doc = couch_doc:from_json_obj(?JSON_DECODE(DocBytes)),
-        % we'll send the Parser process ID to the remote nodes so they can
-        % retrieve their own copies of the attachment data
-        WithParser = fun(follows) -> {follows, Parser, Ref}; (D) -> D end,
-        Atts = [couch_att:transform(data, WithParser, A) || A <- Doc#doc.atts],
-        WaitFun = fun() ->
-            receive {'DOWN', ParserRef, _, _, _} -> ok end,
-            erlang:put(mochiweb_request_recv, true)
-        end,
-        {ok, Doc#doc{atts=Atts}, WaitFun, Parser};
+        %% FIXME: How to remove the knowledge about this message?
+        {{started_open_doc_revs, NewRef}, Parser, ParserRef};
+    {doc_bytes, Ref, DocBytes}  ->
+        {{doc_bytes, Ref, DocBytes}, Parser, ParserRef};
     {'DOWN', ParserRef, _, _, normal} ->
         ok;
     {'DOWN', ParserRef, process, Parser, {{nocatch, {Error, Msg}}, _}} ->


Mime
View raw message