aboutsummaryrefslogtreecommitdiff
path: root/src/node_flat.erl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2021-08-22 12:44:50 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2021-08-22 12:44:50 +0200
commit8d5025076f53abc0474c86a0f879ff1736714844 (patch)
tree06b8c8d9c4c4275d42e208628ad47aafdaf5e468 /src/node_flat.erl
parentPubSub: Optimize publishing on large nodes (SQL) (diff)
PubSub: Add delete_old_pubsub_items command
Add a command for keeping only the specified number of items on each node and removing all older items. This might be especially useful if nodes may be configured to have no 'max_items' limit. Thanks to Ammonit Measurement GmbH for sponsoring this work.
Diffstat (limited to 'src/node_flat.erl')
-rw-r--r--src/node_flat.erl13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/node_flat.erl b/src/node_flat.erl
index fe08be258..97f149f9c 100644
--- a/src/node_flat.erl
+++ b/src/node_flat.erl
@@ -39,7 +39,8 @@
-export([init/3, terminate/2, options/0, features/0,
create_node_permission/6, create_node/2, delete_node/1,
purge_node/2, subscribe_node/8, unsubscribe_node/4,
- publish_item/7, delete_item/4, remove_extra_items/3,
+ publish_item/7, delete_item/4,
+ remove_extra_items/2, remove_extra_items/3,
get_entity_affiliations/2, get_node_affiliations/1,
get_affiliation/2, set_affiliation/3,
get_entity_subscriptions/2, get_node_subscriptions/1,
@@ -403,6 +404,16 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload,
end
end.
+remove_extra_items(Nidx, MaxItems) ->
+ {result, States} = get_states(Nidx),
+ Records = States ++ mnesia:read({pubsub_orphan, Nidx}),
+ ItemIds = lists:flatmap(fun(#pubsub_state{items = Is}) ->
+ Is;
+ (#pubsub_orphan{items = Is}) ->
+ Is
+ end, Records),
+ remove_extra_items(Nidx, MaxItems, ItemIds).
+
%% @doc <p>This function is used to remove extra items, most notably when the
%% maximum number of items has been reached.</p>
%% <p>This function is used internally by the core PubSub module, as no