From ebc9d5bac1a69ba25044a73674b8e9ea18217f60 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Sat, 25 Oct 2014 23:56:41 +0200 Subject: Optimize fetchnewentries --- src/index.erl | 11 +++++++++++ src/storage.erl | 11 ++--------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/index.erl b/src/index.erl index bbc9a10..c1e0352 100644 --- a/src/index.erl +++ b/src/index.erl @@ -77,6 +77,17 @@ decodedata(<<_:?ENTRYSIZE/binary-unit:16, _>>, _Acc) -> util:exit_with_error(badformat, readindex, "Index line not ending with linefeed"). +-spec size(string()) -> integer(). +size(Basepath) -> + case file:open(Basepath, [read, binary]) of + {ok, File} -> + {ok, Filesize} = file:position(File, eof), + Filesize mod ?ENTRYSIZEINFILE; + {error, Error} -> + util:exit_with_error(Error, readfile, + "Error opening file for reading") + end. + -spec get(string(), integer()) -> binary(). get(Basepath, Index) -> case getrange(Basepath, Index, Index) of diff --git a/src/storage.erl b/src/storage.erl index e09acdb..df6641a 100644 --- a/src/storage.erl +++ b/src/storage.erl @@ -43,15 +43,8 @@ request(get, "ct/storage/fetchnewentries", _Input) -> {entries, Entries}]}). fetchnewhashes(Index) -> - lists:reverse(fetchnewhashes(Index, [])). - -fetchnewhashes(Index, Acc) -> - case index:get(newentries_path(), Index) of - noentry -> - Acc; - Entry -> - fetchnewhashes(Index + 1, [Entry | Acc]) - end. + Size = index:size(newentries_path()), + index:getrange(newentries_path(), Index, Size - 1). %% Private functions. html(Text, Input) -> -- cgit v1.1