You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2020/04/23 12:49:54 UTC
[GitHub] [couchdb] garrensmith commented on a change in pull request #2799: Add fold_docs for DocId list
garrensmith commented on a change in pull request #2799:
URL: https://github.com/apache/couchdb/pull/2799#discussion_r413770836
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -902,9 +902,10 @@ send_all_docs_keys(Db, #mrargs{} = Args, VAcc0) ->
_ -> Args#mrargs.doc_options
end,
IncludeDocs = Args#mrargs.include_docs,
- lists:foldl(fun(DocId, Acc) ->
- OpenOpts = [deleted | DocOpts],
- Row0 = case fabric2_db:open_doc(Db, DocId, OpenOpts) of
+ OpenOpts = [deleted | DocOpts],
+
+ CB = fun({doc, DocId, Doc}, Acc) ->
Review comment:
Fixed
##########
File path: src/fabric/src/fabric2_db.erl
##########
@@ -969,6 +970,145 @@ fold_docs(Db, UserFun, UserAcc0, Options) ->
end).
+fold_docs(Db, DocIds, UserFun, UserAcc0, Options) ->
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ try
+ NeedsTreeOpts = [revs_info, conflicts, deleted_conflicts],
+ NeedsTree = (Options -- NeedsTreeOpts /= Options),
+
+ FetchRevs = case NeedsTree of
+ true ->
+ fun(DocId) ->
+ fabric2_fdb:get_all_revs_future(TxDb, DocId)
Review comment:
Good spot. Fixed
##########
File path: test/elixir/test/all_docs_test.exs
##########
@@ -242,13 +262,17 @@ defmodule AllDocsTest do
resp = Couch.post(
"/#{db_name}/_all_docs",
body: %{
- :keys => [1, 2],
- :limit => 1
+ :keys => ["1", "2"],
Review comment:
The original test was just returning `%{"error" => "not_found", "key" => 1}` which is not quite what we should be testing. We should be testing we return the document for that key. So I've added in the test to check that we return an error for the incorrect key and a proper test to prove we return keys. No functionality changed. Just improving the tests.
##########
File path: src/fabric/src/fabric2_db.erl
##########
@@ -969,6 +970,145 @@ fold_docs(Db, UserFun, UserAcc0, Options) ->
end).
+fold_docs(Db, DocIds, UserFun, UserAcc0, Options) ->
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ try
+ NeedsTreeOpts = [revs_info, conflicts, deleted_conflicts],
+ NeedsTree = (Options -- NeedsTreeOpts /= Options),
+
+ FetchRevs = case NeedsTree of
+ true ->
+ fun(DocId) ->
+ fabric2_fdb:get_all_revs_future(TxDb, DocId)
+ end;
+ false ->
+ fun(DocId) ->
+ fabric2_fdb:get_winning_revs_future(TxDb, DocId, 1)
+ end
+ end,
+ InitAcc = #{
+ revs_q => queue:new(),
+ revs_count => 0,
+ body_q => queue:new(),
+ body_count => 0,
+ doc_opts => Options,
+ user_acc => UserAcc0,
+ user_fun => UserFun
+ },
+
+ FinalAcc1 = lists:foldl(fun(DocId, Acc) ->
+ #{
+ revs_q := RevsQ,
+ revs_count := RevsCount
+ } = Acc,
+ Future = FetchRevs(DocId),
+ NewAcc = Acc#{
+ revs_q := queue:in({DocId, Future}, RevsQ),
+ revs_count := RevsCount + 1
+ },
+ drain_fold_docs_revs_futures(TxDb, NewAcc)
+ end, InitAcc, DocIds),
+
+ FinalAcc2 = drain_all_fold_docs_revs_futures(TxDb, FinalAcc1),
+ FinalAcc3 = drain_all_fold_docs_body_futures(TxDb, FinalAcc2),
+
+ #{
+ user_acc := FinalUserAcc
+ } = FinalAcc3,
+ {ok, FinalUserAcc}
+
+ catch throw:{stop, StopUserAcc} ->
+ {ok, StopUserAcc}
+ end
+ end).
+
+
+drain_fold_docs_revs_futures(_TxDb, #{revs_count := C} = Acc) when C < 100 ->
Review comment:
Fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org