summaryrefslogtreecommitdiff
path: root/src/mod_client_state.erl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2017-04-06 21:01:26 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2017-04-06 21:01:26 +0200
commit7827faae4b5c7040defffab29872656d04a6ce72 (patch)
tree7f607cd59a15d6190d3b5b8f8b1a7f36762d6aa0 /src/mod_client_state.erl
parentImprove type specs and return values (diff)
mod_client_state: Don't keep track of queue size
Use maps:size/1 rather than keeping track of the size ourselves.
Diffstat (limited to '')
-rw-r--r--src/mod_client_state.erl20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/mod_client_state.erl b/src/mod_client_state.erl
index bbce7259..a5ac611f 100644
--- a/src/mod_client_state.erl
+++ b/src/mod_client_state.erl
@@ -47,7 +47,7 @@
-define(CSI_QUEUE_MAX, 100).
-type csi_type() :: presence | chatstate | {pep, binary()}.
--type csi_queue() :: {non_neg_integer(), non_neg_integer(), map()}.
+-type csi_queue() :: {non_neg_integer(), map()}.
-type csi_timestamp() :: {non_neg_integer(), erlang:timestamp()}.
-type c2s_state() :: ejabberd_c2s:state().
-type filter_acc() :: {stanza() | drop, c2s_state()}.
@@ -379,43 +379,43 @@ get_pep_node(#message{} = Msg) ->
%%--------------------------------------------------------------------
-spec queue_new() -> csi_queue().
queue_new() ->
- {0, 0, #{}}.
+ {0, #{}}.
-spec queue_in(term(), term(), term(), csi_queue()) -> csi_queue().
-queue_in(Key, Type, Val, {N, Seq, Q}) ->
+queue_in(Key, Type, Val, {Seq, Q}) ->
Seq1 = Seq + 1,
Time = {Seq1, p1_time_compat:timestamp()},
case maps:get(Key, Q, error) of
error ->
Q1 = maps:put(Key, [{Type, Time, Val}], Q),
- {N + 1, Seq1, Q1};
+ {Seq1, Q1};
TypeVals ->
case lists:keymember(Type, 1, TypeVals) of
true ->
TypeVals1 = lists:keyreplace(
Type, 1, TypeVals, {Type, Time, Val}),
Q1 = maps:put(Key, TypeVals1, Q),
- {N, Seq1, Q1};
+ {Seq1, Q1};
false ->
TypeVals1 = [{Type, Time, Val}|TypeVals],
Q1 = maps:put(Key, TypeVals1, Q),
- {N + 1, Seq1, Q1}
+ {Seq1, Q1}
end
end.
-spec queue_take(term(), csi_queue()) -> {list(), csi_queue()} | error.
-queue_take(Key, {N, Seq, Q}) ->
+queue_take(Key, {Seq, Q}) ->
case maps:get(Key, Q, error) of
error ->
error;
TypeVals ->
Q1 = maps:remove(Key, Q),
- {lists:keysort(2, TypeVals), {N-length(TypeVals), Seq, Q1}}
+ {lists:keysort(2, TypeVals), {Seq, Q1}}
end.
-spec queue_len(csi_queue()) -> non_neg_integer().
-queue_len({N, _, _}) ->
- N.
+queue_len({_, Q}) ->
+ maps:size(Q).
-spec queue_to_list(csi_queue()) -> [term()].
queue_to_list({_, _, Q}) ->