aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2021-08-21 12:29:37 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2021-08-21 12:29:37 +0200
commit1b0e59bb139f83d1f027ece08606446c30d35ae5 (patch)
treedf7351c46b33ec9e064c60755bc5841789882bcf /src
parentPubSub: Support 'max_items=max' node configuration (diff)
PubSub: Support unlimited number of items
Allow for setting the mod_pubsub option 'max_items_node' to 'unlimited'. If clients then request a 'max_items' limit of 'max', old items aren't deleted when publishing new ones. Thanks to Ammonit Measurement GmbH for sponsoring this work.
Diffstat (limited to 'src')
-rw-r--r--src/mod_pubsub.erl14
-rw-r--r--src/node_flat.erl3
-rw-r--r--src/node_flat_sql.erl3
3 files changed, 12 insertions, 8 deletions
diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl
index 49a54c9b4..c6f485077 100644
--- a/src/mod_pubsub.erl
+++ b/src/mod_pubsub.erl
@@ -210,7 +210,7 @@
pep_mapping :: [{binary(), binary()}],
ignore_pep_from_offline :: boolean(),
last_item_cache :: boolean(),
- max_items_node :: non_neg_integer(),
+ max_items_node :: non_neg_integer()|unlimited,
max_subscriptions_node :: non_neg_integer()|undefined,
default_node_config :: [{atom(), binary()|boolean()|integer()|atom()}],
nodetree :: binary(),
@@ -3399,7 +3399,7 @@ node_config(_, _, []) ->
%% @doc <p>Return the maximum number of items for a given node.</p>
%% <p>Unlimited means that there is no limit in the number of items that can
%% be stored.</p>
--spec max_items(host(), [{atom(), any()}]) -> non_neg_integer().
+-spec max_items(host(), [{atom(), any()}]) -> non_neg_integer() | unlimited.
max_items(Host, Options) ->
case get_option(Options, persist_items) of
true ->
@@ -3549,16 +3549,18 @@ decode_get_pending(#xdata{fields = Fs}, Lang) ->
end.
-spec check_opt_range(atom(), [proplists:property()],
- non_neg_integer() | undefined) -> boolean().
+ non_neg_integer() | unlimited | undefined) -> boolean().
check_opt_range(_Opt, _Opts, undefined) ->
true;
+check_opt_range(_Opt, _Opts, unlimited) ->
+ true;
check_opt_range(Opt, Opts, Max) ->
case proplists:get_value(Opt, Opts, Max) of
max -> true;
Val -> Val =< Max
end.
--spec get_max_items_node(host()) -> undefined | non_neg_integer().
+-spec get_max_items_node(host()) -> undefined | unlimited | non_neg_integer().
get_max_items_node(Host) ->
config(Host, max_items_node, undefined).
@@ -4150,7 +4152,7 @@ mod_opt_type(ignore_pep_from_offline) ->
mod_opt_type(last_item_cache) ->
econf:bool();
mod_opt_type(max_items_node) ->
- econf:non_neg_int();
+ econf:non_neg_int(unlimited);
mod_opt_type(max_nodes_discoitems) ->
econf:non_neg_int(infinity);
mod_opt_type(max_subscriptions_node) ->
@@ -4277,7 +4279,7 @@ mod_doc() ->
"and allows to raise user connection rate. The cost "
"is memory usage, as every item is stored in memory.")}},
{max_items_node,
- #{value => "MaxItems",
+ #{value => "non_neg_integer() | infinity",
desc =>
?T("Define the maximum number of items that can be "
"stored in a node. Default value is: '10'.")}},
diff --git a/src/node_flat.erl b/src/node_flat.erl
index 4a2a60971..fe08be258 100644
--- a/src/node_flat.erl
+++ b/src/node_flat.erl
@@ -375,7 +375,8 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload,
or (Subscribed == true)) ->
{error, xmpp:err_forbidden()};
true ->
- if MaxItems > 0 ->
+ if MaxItems > 0;
+ MaxItems == unlimited ->
Now = erlang:timestamp(),
case get_item(Nidx, ItemId) of
{result, #pubsub_item{creation = {_, GenKey}} = OldItem} ->
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl
index 1e197a51d..1309c2886 100644
--- a/src/node_flat_sql.erl
+++ b/src/node_flat_sql.erl
@@ -247,7 +247,8 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload,
or (Subscribed == true)) ->
{error, xmpp:err_forbidden()};
true ->
- if MaxItems > 0 ->
+ if MaxItems > 0;
+ MaxItems == unlimited ->
Now = erlang:timestamp(),
case get_item(Nidx, ItemId) of
{result, #pubsub_item{creation = {_, GenKey}} = OldItem} ->