diff --git a/src/sumo_store_mnesia.erl b/src/sumo_store_mnesia.erl index 1c001d4..89a65c1 100644 --- a/src/sumo_store_mnesia.erl +++ b/src/sumo_store_mnesia.erl @@ -143,16 +143,20 @@ find_by(DocName, Conditions, Limit, Offset, State) -> sumo_store:result([sumo_internal:doc()], state()). find_by(DocName, Conditions, [], Limit, Offset, State) -> MatchSpec = build_match_spec(DocName, Conditions), + Transaction0 = fun() -> mnesia:select(DocName, MatchSpec) end, + TransactionL = + fun() -> + case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of + {ManyItems, _Cont} -> + lists:sublist(ManyItems, Offset + 1, Limit); + '$end_of_table' -> + [] + end + end, Transaction = case Limit of - 0 -> - fun() -> mnesia:select(DocName, MatchSpec) end; - Limit -> - fun() -> - {ManyItems, _Cont} = - mnesia:select(DocName, MatchSpec, Offset + Limit, read), - lists:sublist(ManyItems, Offset + 1, Limit) - end + 0 -> Transaction0; + Limit -> TransactionL end, case mnesia:transaction(Transaction) of {aborted, Reason} -> diff --git a/test/sumo_basic_SUITE.erl b/test/sumo_basic_SUITE.erl index ad65643..814c076 100644 --- a/test/sumo_basic_SUITE.erl +++ b/test/sumo_basic_SUITE.erl @@ -8,6 +8,7 @@ ]). -export([ + find/1, find_all/1, find_by/1, delete_all/1, @@ -54,6 +55,9 @@ end_per_suite(Config) -> %%% Exported Tests Functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +find(_Config) -> + run_all_stores(fun find_module/1). + find_all(_Config) -> run_all_stores(fun find_all_module/1). @@ -84,6 +88,12 @@ init_store(Module) -> %% Sync Timeout. sync_timeout(Module). +find_module(Module) -> + [First, Second | _] = sumo:find_all(Module), + First = sumo:find(Module, Module:id(First)), + Second = sumo:find(Module, Module:id(Second)), + notfound = sumo:find(Module, 0). + find_all_module(Module) -> 6 = length(sumo:find_all(Module)).