Skip to content

Commit

Permalink
Add a note about partially bound key select
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed May 18, 2022
1 parent 35a4a83 commit 47bee10
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ejabberd_sm_cets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ get_sessions() ->

-spec get_sessions(jid:lserver()) -> [ejabberd_sm:session()].
get_sessions(Server) ->
%% This is not a full table scan. From the ETS docs:
%% For ordered_set a partially bound key will limit the traversal to only
%% scan a subset of the table based on term order.
%% A partially bound key is either a list or a tuple with
%% a prefix that is fully bound.
R = {{Server, '_', '_', '_'}, '_', '_'},
Xs = ets:select(?TABLE, [{R, [], ['$_']}]),
tuples_to_sessions(Xs).
Expand Down Expand Up @@ -98,6 +103,7 @@ cleanup(Node) ->
Guard = {'==', {node, '$1'}, Node},
R = {KeyPattern, '_', '_'},
cets:sync(?TABLE),
%% This is a full table scan, but cleanup is rare.
Tuples = ets:select(?TABLE, [{R, [Guard], ['$_']}]),
Keys = lists:map(fun({Key, _, _} = Tuple) ->
Session = tuple_to_session(Tuple),
Expand Down

0 comments on commit 47bee10

Please sign in to comment.