mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
For pubsub items with max_item = 1 use order by in sql queries
This commit is contained in:
parent
48bed43902
commit
51bf552c3f
@ -186,6 +186,9 @@
|
|||||||
-callback get_last_items(nodeIdx(), jid(), undefined | rsm_set()) ->
|
-callback get_last_items(nodeIdx(), jid(), undefined | rsm_set()) ->
|
||||||
{result, [pubsubItem()]}.
|
{result, [pubsubItem()]}.
|
||||||
|
|
||||||
|
-callback get_only_item(nodeIdx(), jid()) ->
|
||||||
|
{result, [pubsubItem()]}.
|
||||||
|
|
||||||
-callback get_item(NodeIdx :: nodeIdx(),
|
-callback get_item(NodeIdx :: nodeIdx(),
|
||||||
ItemId :: itemId(),
|
ItemId :: itemId(),
|
||||||
JID :: jid(),
|
JID :: jid(),
|
||||||
|
@ -2151,6 +2151,21 @@ get_last_items(Host, Type, Nidx, LJID, Count) when Count > 1 ->
|
|||||||
get_last_items(_Host, _Type, _Nidx, _LJID, _Count) ->
|
get_last_items(_Host, _Type, _Nidx, _LJID, _Count) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
|
-spec get_only_item(host(), binary(), nodeIdx(), ljid()) -> [#pubsub_item{}].
|
||||||
|
get_only_item(Host, Type, Nidx, LJID) ->
|
||||||
|
case get_cached_item(Host, Nidx) of
|
||||||
|
undefined ->
|
||||||
|
case node_action(Host, Type, get_only_item, [Nidx, LJID]) of
|
||||||
|
{result, Items} when length(Items) < 2 ->
|
||||||
|
Items;
|
||||||
|
{result, Items} ->
|
||||||
|
[hd(lists:keysort(#pubsub_item.modification, Items))];
|
||||||
|
_ -> []
|
||||||
|
end;
|
||||||
|
LastItem ->
|
||||||
|
[LastItem]
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc <p>Return the list of affiliations as an XMPP response.</p>
|
%% @doc <p>Return the list of affiliations as an XMPP response.</p>
|
||||||
-spec get_affiliations(host(), binary(), jid(), [binary()]) ->
|
-spec get_affiliations(host(), binary(), jid(), [binary()]) ->
|
||||||
{result, pubsub()} | {error, stanza_error()}.
|
{result, pubsub()} | {error, stanza_error()}.
|
||||||
@ -3031,7 +3046,13 @@ c2s_handle_info(C2SState, _) ->
|
|||||||
send_items(Host, Node, Nidx, Type, Options, LJID, Number) ->
|
send_items(Host, Node, Nidx, Type, Options, LJID, Number) ->
|
||||||
send_items(Host, Node, Nidx, Type, Options, Host, LJID, LJID, Number).
|
send_items(Host, Node, Nidx, Type, Options, Host, LJID, LJID, Number).
|
||||||
send_items(Host, Node, Nidx, Type, Options, Publisher, SubLJID, ToLJID, Number) ->
|
send_items(Host, Node, Nidx, Type, Options, Publisher, SubLJID, ToLJID, Number) ->
|
||||||
case get_last_items(Host, Type, Nidx, SubLJID, Number) of
|
Items = case max_items(Host, Options) of
|
||||||
|
1 ->
|
||||||
|
get_only_item(Host, Type, Nidx, SubLJID);
|
||||||
|
_ ->
|
||||||
|
get_last_items(Host, Type, Nidx, SubLJID, Number)
|
||||||
|
end,
|
||||||
|
case Items of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
Items ->
|
Items ->
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
get_last_items/3,
|
get_last_items/3, get_only_item/2,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, can_fetch_item/2, is_subscribed/1, transform/1]).
|
path_to_node/1, can_fetch_item/2, is_subscribed/1, transform/1]).
|
||||||
|
|
||||||
@ -812,6 +812,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM
|
|||||||
get_items(Nidx, JID, RSM)
|
get_items(Nidx, JID, RSM)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
get_only_item(Nidx, From) ->
|
||||||
|
get_last_items(Nidx, From, 1).
|
||||||
|
|
||||||
get_last_items(Nidx, _From, Count) when Count > 0 ->
|
get_last_items(Nidx, _From, Count) when Count > 0 ->
|
||||||
Items = mnesia:index_read(pubsub_item, Nidx, #pubsub_item.nodeidx),
|
Items = mnesia:index_read(pubsub_item, Nidx, #pubsub_item.nodeidx),
|
||||||
LastItems = lists:reverse(lists:keysort(#pubsub_item.modification, Items)),
|
LastItems = lists:reverse(lists:keysort(#pubsub_item.modification, Items)),
|
||||||
|
@ -51,7 +51,8 @@
|
|||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1,
|
path_to_node/1,
|
||||||
get_entity_subscriptions_for_send_last/2, get_last_items/3]).
|
get_entity_subscriptions_for_send_last/2, get_last_items/3,
|
||||||
|
get_only_item/2]).
|
||||||
|
|
||||||
-export([decode_jid/1, encode_jid/1, encode_jid_like/1,
|
-export([decode_jid/1, encode_jid/1, encode_jid_like/1,
|
||||||
decode_affiliation/1, decode_subscriptions/1,
|
decode_affiliation/1, decode_subscriptions/1,
|
||||||
@ -741,6 +742,25 @@ get_last_items(Nidx, _From, Limit) ->
|
|||||||
{result, []}
|
{result, []}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
get_only_item(Nidx, _From) ->
|
||||||
|
SNidx = misc:i2l(Nidx),
|
||||||
|
Query = fun(mssql, _) ->
|
||||||
|
ejabberd_sql:sql_query_t(
|
||||||
|
[<<"select itemid, publisher, creation, modification, payload",
|
||||||
|
" from pubsub_item where nodeid='", SNidx/binary, "'">>]);
|
||||||
|
(_, _) ->
|
||||||
|
ejabberd_sql:sql_query_t(
|
||||||
|
[<<"select itemid, publisher, creation, modification, payload",
|
||||||
|
" from pubsub_item where nodeid='", SNidx/binary, "'">>])
|
||||||
|
end,
|
||||||
|
case catch ejabberd_sql:sql_query_t(Query) of
|
||||||
|
{selected, [<<"itemid">>, <<"publisher">>, <<"creation">>,
|
||||||
|
<<"modification">>, <<"payload">>], RItems} ->
|
||||||
|
{result, [raw_to_item(Nidx, RItem) || RItem <- RItems]};
|
||||||
|
_ ->
|
||||||
|
{result, []}
|
||||||
|
end.
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
case catch ejabberd_sql:sql_query_t(
|
case catch ejabberd_sql:sql_query_t(
|
||||||
?SQL("select @(itemid)s, @(publisher)s, @(creation)s,"
|
?SQL("select @(itemid)s, @(publisher)s, @(creation)s,"
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
get_subscriptions/2, set_subscriptions/4,
|
get_subscriptions/2, set_subscriptions/4,
|
||||||
get_pending_nodes/2, get_states/1, get_state/2,
|
get_pending_nodes/2, get_states/1, get_state/2,
|
||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
get_last_items/3,
|
get_last_items/3, get_only_item/2,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, depends/3]).
|
path_to_node/1, depends/3]).
|
||||||
|
|
||||||
@ -231,6 +231,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
get_last_items(Nidx, From, Count) ->
|
get_last_items(Nidx, From, Count) ->
|
||||||
node_flat:get_last_items(Nidx, From, Count).
|
node_flat:get_last_items(Nidx, From, Count).
|
||||||
|
|
||||||
|
get_only_item(Nidx, From) ->
|
||||||
|
node_flat:get_only_item(Nidx, From).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat:get_item(Nidx, ItemId).
|
node_flat:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@
|
|||||||
set_state/1, get_items/7, get_items/3, get_item/7,
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
||||||
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
||||||
path_to_node/1, depends/3,
|
path_to_node/1, depends/3,
|
||||||
get_entity_subscriptions_for_send_last/2, get_last_items/3]).
|
get_entity_subscriptions_for_send_last/2, get_last_items/3,
|
||||||
|
get_only_item/2]).
|
||||||
|
|
||||||
depends(_Host, _ServerHost, _Opts) ->
|
depends(_Host, _ServerHost, _Opts) ->
|
||||||
[{mod_caps, hard}].
|
[{mod_caps, hard}].
|
||||||
@ -218,6 +219,9 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM)
|
|||||||
get_last_items(Nidx, JID, Count) ->
|
get_last_items(Nidx, JID, Count) ->
|
||||||
node_flat_sql:get_last_items(Nidx, JID, Count).
|
node_flat_sql:get_last_items(Nidx, JID, Count).
|
||||||
|
|
||||||
|
get_only_item(Nidx, JID) ->
|
||||||
|
node_flat_sql:get_only_item(Nidx, JID).
|
||||||
|
|
||||||
get_item(Nidx, ItemId) ->
|
get_item(Nidx, ItemId) ->
|
||||||
node_flat_sql:get_item(Nidx, ItemId).
|
node_flat_sql:get_item(Nidx, ItemId).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user