couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject couch commit: updated refs/heads/add-filter-revs-limit to bb82dd6
Date Tue, 29 Sep 2015 20:37:38 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/add-filter-revs-limit [created] bb82dd6ae


Add revs limit for docs passed to filter functions

The existing revs_limit logic only accounts for depth of individual
branches, and ignores the case where you have a lot of branches, for
instance when a doc is heavily conflicted. This patch truncates the list
of revs when passing docs to the JS filter functions, because given
enough revs this can cause the couchjs processes to explode.


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

Branch: refs/heads/add-filter-revs-limit
Commit: bb82dd6ae52d2d5b12ca6d16941c5f7fa2ea10ae
Parents: 9afa6a0
Author: Russell Branca <chewbranca@apache.org>
Authored: Tue Sep 29 20:32:02 2015 +0000
Committer: Russell Branca <chewbranca@apache.org>
Committed: Tue Sep 29 20:32:02 2015 +0000

----------------------------------------------------------------------
 src/couch_doc.erl           | 17 ++++++++++++-----
 src/couch_query_servers.erl |  3 ++-
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bb82dd6a/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index a982616..ecfb176 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -48,14 +48,21 @@ to_json_body(true, {Body}) ->
 to_json_body(false, {Body}) ->
     Body.
 
-to_json_revisions(Options, Start, RevIds) ->
-    case lists:member(revs, Options) of
-    false -> [];
-    true ->
+to_json_revisions(Options, Start, RevIds0) ->
+    RevIds = case proplists:get_value(revs, Options) of
+        true ->
+            RevIds0;
+        Num when is_integer(Num), Num > 0 ->
+            lists:sublist(RevIds0, Num);
+        _ ->
+           []
+    end,
+    if RevIds == [] -> []; true ->
         [{<<"_revisions">>, {[{<<"start">>, Start},
-                {<<"ids">>, [revid_to_str(R) ||R <- RevIds]}]}}]
+            {<<"ids">>, [revid_to_str(R) ||R <- RevIds]}]}}]
     end.
 
+
 revid_to_str(RevId) when size(RevId) =:= 16 ->
     ?l2b(couch_util:to_hex(RevId));
 revid_to_str(RevId) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bb82dd6a/src/couch_query_servers.erl
----------------------------------------------------------------------
diff --git a/src/couch_query_servers.erl b/src/couch_query_servers.erl
index 4882f9e..6842e8d 100644
--- a/src/couch_query_servers.erl
+++ b/src/couch_query_servers.erl
@@ -296,7 +296,8 @@ filter_docs(Req, Db, DDoc, FName, Docs) ->
     #httpd{} = HttpReq ->
         couch_httpd_external:json_req_obj(HttpReq, Db)
     end,
-    JsonDocs = [couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs],
+    Limit = config:get_integer("couchdb", "filter_revs_limit", 20),
+    JsonDocs = [couch_doc:to_json_obj(Doc, [{revs, Limit}]) || Doc <- Docs],
     [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName],
         [JsonDocs, JsonReq]),
     {ok, Passes}.


Mime
View raw message