couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r727182 - /couchdb/trunk/src/couchdb/couch_rep.erl
Date Tue, 16 Dec 2008 21:55:38 GMT
Author: jchris
Date: Tue Dec 16 13:55:37 2008
New Revision: 727182

URL: http://svn.apache.org/viewvc?rev=727182&view=rev
Log:
fix COUCHDB-174 thanks Adam Kocoloski

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=727182&r1=727181&r2=727182&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Tue Dec 16 13:55:37 2008
@@ -379,9 +379,30 @@
             % latest is only option right now
             "latest=true"
         end, Options),
-    RevsQueryStrs = lists:flatten(?JSON_ENCODE(Revs)),
-    Url = DbUrl ++ url_encode(DocId) ++ "?" ++ couch_util:implode(["revs=true", "attachments=true",
"open_revs=" ++ RevsQueryStrs ] ++ QueryOptionStrs, "&"),
-    JsonResults = do_http_request(Url, get, Headers),
+    
+    BaseUrl = DbUrl ++ url_encode(DocId) ++ "?" ++ couch_util:implode(
+        ["revs=true", "attachments=true"] ++ QueryOptionStrs, "&"),
+    
+    %% MochiWeb expects URLs < 8KB long, so maybe split into multiple requests
+    MaxN = trunc((8192 - length(BaseUrl))/14),
+    
+    JsonResults = case length(Revs) > MaxN of
+    false ->
+        Url = BaseUrl ++ "&open_revs=" ++ lists:flatten(?JSON_ENCODE(Revs)),
+        do_http_request(Url, get, Headers);
+    true ->
+        {_, Rest, Acc} = lists:foldl(
+        fun(Rev, {Count, RevsAcc, AccResults}) when Count =:= MaxN ->
+            QSRevs = lists:flatten(?JSON_ENCODE(lists:reverse(RevsAcc))),
+            Url = BaseUrl ++ "&open_revs=" ++ QSRevs,
+            {1, [Rev], AccResults++do_http_request(Url, get, Headers)};
+        (Rev, {Count, RevsAcc, AccResults}) ->
+            {Count+1, [Rev|RevsAcc], AccResults}
+        end, {0, [], []}, Revs),
+        Acc ++ do_http_request(BaseUrl ++ "&open_revs=" ++ 
+            lists:flatten(?JSON_ENCODE(lists:reverse(Rest))), get, Headers)
+    end,
+    
     Results =
     lists:map(
         fun({[{<<"missing">>, Rev}]}) ->



Mime
View raw message