diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2021-08-21 20:02:58 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2021-08-21 20:02:58 +0200 |
commit | 29751a6174d181f80bbcde7c92f8cc958eee85a1 (patch) | |
tree | 15eb2bae21590d9dcb7080be21d9aa63011a2716 /src/node_flat_sql.erl | |
parent | PubSub: Support unlimited number of items (diff) |
PubSub: Optimize publishing on large nodes (SQL)
Avoid an unnecessary SQL query while publishing an item on a PubSub node
without 'max_items' limit. The query in question can be expensive if
the node has a large number of items.
Thanks to Ammonit Measurement GmbH for sponsoring this work.
Diffstat (limited to 'src/node_flat_sql.erl')
-rw-r--r-- | src/node_flat_sql.erl | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl index 1309c288..5033eda5 100644 --- a/src/node_flat_sql.erl +++ b/src/node_flat_sql.erl @@ -259,14 +259,14 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload, {result, _} -> {error, xmpp:err_forbidden()}; _ -> - Items = [ItemId | itemids(Nidx, GenKey)], - {result, {_NI, OI}} = remove_extra_items(Nidx, MaxItems, Items), + OldIds = maybe_remove_extra_items(Nidx, MaxItems, + GenKey, ItemId), set_item(#pubsub_item{ itemid = {ItemId, Nidx}, creation = {Now, GenKey}, modification = {Now, SubKey}, payload = Payload}), - {result, {default, broadcast, OI}} + {result, {default, broadcast, OldIds}} end; true -> {result, {default, broadcast, []}} @@ -934,6 +934,16 @@ update_subscription(Nidx, JID, Subscription) -> "-affiliation='n'" ]). +-spec maybe_remove_extra_items(mod_pubsub:nodeIdx(), + non_neg_integer() | unlimited, ljid(), + mod_pubsub:itemId()) -> [mod_pubsub:itemId()]. +maybe_remove_extra_items(_Nidx, unlimited, _GenKey, _ItemId) -> + []; +maybe_remove_extra_items(Nidx, MaxItems, GenKey, ItemId) -> + ItemIds = [ItemId | itemids(Nidx, GenKey)], + {result, {_NewIds, OldIds}} = remove_extra_items(Nidx, MaxItems, ItemIds), + OldIds. + -spec decode_jid(SJID :: binary()) -> ljid(). decode_jid(SJID) -> jid:tolower(jid:decode(SJID)). |