mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
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.
This commit is contained in:
parent
1b0e59bb13
commit
29751a6174
@ -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)).
|
||||
|
Loading…
Reference in New Issue
Block a user