summaryrefslogtreecommitdiff
path: root/src/node_flat_sql.erl
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2019-07-31 12:20:38 +0200
committerPaweł Chmielowski <pchmielowski@process-one.net>2019-07-31 13:06:44 +0200
commit51bf552c3f3b804af1b89218980ef1d48e892832 (patch)
tree5b9df9850a55bc42b8900052e681d048a6946e6b /src/node_flat_sql.erl
parentDon't render CAPTCHA whitelist when CAPTCHA is not configured (diff)
For pubsub items with max_item = 1 use order by in sql queries
Diffstat (limited to 'src/node_flat_sql.erl')
-rw-r--r--src/node_flat_sql.erl22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl
index 59e3c89b..15d9fd77 100644
--- a/src/node_flat_sql.erl
+++ b/src/node_flat_sql.erl
@@ -51,7 +51,8 @@
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,
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,
decode_affiliation/1, decode_subscriptions/1,
@@ -741,6 +742,25 @@ get_last_items(Nidx, _From, Limit) ->
{result, []}
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) ->
case catch ejabberd_sql:sql_query_t(
?SQL("select @(itemid)s, @(publisher)s, @(creation)s,"