Skip to content

Commit

Permalink
Merge pull request #329 from mvpossum/master
Browse files Browse the repository at this point in the history
Fix find_by when offset is greater than available objects
  • Loading branch information
elbrujohalcon committed Dec 2, 2017
2 parents 2bdbc5f + adb65f6 commit 30eb43a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/adapter_test_helpers/sumo_basic_test_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ find_by(Config) ->
%% Check pagination
Results1 = sumo:find_by(Name, [], 3, 1),
[_, _, _] = Results1,
[_, _, _, _, _, _, _] = sumo:find_by(Name, [], 1000, 1),
[] = sumo:find_by(Name, [], 1, 1000),

%% This test is #177 github issue related
[_, _, _, _, _, _, _, _] = sumo:find_by(Name, []),
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/sumo_store_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ find_by(DocName, Conditions, [], Limit, Offset, State) ->
end,
TransactionL = fun() ->
case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of
{ManyItems, _Cont} ->
{ManyItems, _Cont} when length(ManyItems) >= Offset ->
lists:sublist(ManyItems, Offset + 1, Limit);
{_ManyItems, _Cont} ->
[];
'$end_of_table' ->
[]
end
Expand Down

0 comments on commit 30eb43a

Please sign in to comment.