This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/fdb-layer-get-design-docs
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4fb3fc938dfaf73beac370b6086d14e4078df09c
Author: Paul J. Davis <[email protected]>
AuthorDate: Mon Mar 23 14:27:32 2020 -0500

    Implement fabric2_db:get_design_docs/1
    
    This is a more efficient method to get all of the design documents than
    relying on fabric2_db:fold_docs which doesn't load doc bodies in
    parallel.
---
 src/fabric/src/fabric2_db.erl | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 129dea2..6b69437 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -80,9 +80,7 @@
     get_full_doc_info/2,
     get_full_doc_infos/2,
     get_missing_revs/2,
-    %% get_design_doc/2,
-    %% get_design_docs/1,
-    %% get_design_doc_count/1,
+    get_design_docs/1,
     %% get_purge_infos/2,
 
     %% get_minimum_purge_seq/1,
@@ -657,6 +655,28 @@ get_missing_revs(Db, JsonIdRevs) ->
     {ok, AllMissing}.
 
 
+get_design_docs(Db) ->
+    fabric2_fdb:transactional(Db, fun(TxDb) ->
+        #{
+            db_prefix := DbPrefix
+        } = TxDb,
+
+        Prefix = erlfdb_tuple:pack({?DB_CHANGES}, DbPrefix),
+        Options = set_design_doc_keys([]),
+        FoldFun = fun({Key, Val}, Acc) ->
+            {DocId} = erlfdb_tuple:unpack(K, Prefix),
+            RevId = erlfdb_tuple:unpack(V),
+            Future = get_doc_body_future(TxDb, DocId, RevId),
+            [Future | Acc]
+        end,
+        {ok, Futs} = fabric2_fdb:fold_range(TxDb, Prefix, FoldFun, [], 
Options),
+
+        lists:foldl(fun(Future, Acc) ->
+            [fabric2_fdb:get_doc_body_wait(Future) | Acc]
+        end, [], Futs)
+    end).
+
+
 validate_docid(<<"">>) ->
     throw({illegal_docid, <<"Document id must not be empty">>});
 validate_docid(<<"_design/">>) ->

Reply via email to