From 2483f0cf09ccc4cf73558c7a85bbb51a72d29c3a Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Sat, 25 Oct 2014 15:22:09 +0200 Subject: Optimize db:get_by_indices by not fetching entry and implementing index:getrange --- src/db.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/db.erl') diff --git a/src/db.erl b/src/db.erl index fade7ce..f7c2057 100644 --- a/src/db.erl +++ b/src/db.erl @@ -129,6 +129,9 @@ index_for_leafhash(LeafHash) -> leafhash_for_index(Index) -> index:get(index_path(), Index). +leafhash_for_indices(Start, End) -> + index:getrange(index_path(), Start, End). + leafhash_for_entryhash(EntryHash) -> perm:readfile(entryhash_root_path(), EntryHash). @@ -138,11 +141,10 @@ get_by_indices_helper(Start, End) -> EndBound = min(End, size() - 1), case Start =< EndBound of true -> - lists:map(fun (Index) -> - LeafHash = leafhash_for_index(Index), - Entry = entry_for_leafhash(LeafHash), - {Index, LeafHash, Entry} - end, lists:seq(Start, EndBound)); + lists:map(fun ({LeafHash, Index}) -> + {Index, LeafHash, notfetched} + end, lists:zip(leafhash_for_indices(Start, EndBound), + lists:seq(Start, EndBound))); false -> [] end. -- cgit v1.1