summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2008-12-16 21:55:37 +0000
committerJohn Christopher Anderson <jchris@apache.org>2008-12-16 21:55:37 +0000
commit27dedcf33c085a3cf88809b8e42a86b940a318fe (patch)
tree120363a1605d67bda4031b942b4356b2b1519700 /src/couchdb
parentb7a01abbe508811e8b1748045eebd6dd35030cb2 (diff)
fix COUCHDB-174 thanks Adam Kocoloski
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@727182 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_rep.erl27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index 4fc1cdd6..99cca65d 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -379,9 +379,30 @@ open_doc_revs(#http_db{uri=DbUrl, headers=Headers}, DocId, Revs, Options) ->
% 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}]}) ->