aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2020-01-31 11:43:29 +0100
committerPaweł Chmielowski <pchmielowski@process-one.net>2020-01-31 11:43:41 +0100
commitfdb7e3e3fa2cac5699846bd9dbb94650cdc2398e (patch)
tree7efff6646fc877d58dcfa6e8d69f2fec10f2cddc
parentUpdate copyright to 2020 (#3149) (diff)
Optimize sql queries in pubsub select_affiliation_subscriptions
-rw-r--r--src/node_flat_sql.erl21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/node_flat_sql.erl b/src/node_flat_sql.erl
index 2c9b39e20..c4cc293d0 100644
--- a/src/node_flat_sql.erl
+++ b/src/node_flat_sql.erl
@@ -894,10 +894,23 @@ select_affiliation_subscriptions(Nidx, JID) ->
select_affiliation_subscriptions(Nidx, JID, JID) ->
select_affiliation_subscriptions(Nidx, JID);
select_affiliation_subscriptions(Nidx, GenKey, SubKey) ->
- {result, Affiliation} = get_affiliation(Nidx, GenKey),
- {result, BareJidSubs} = get_subscriptions(Nidx, GenKey),
- {result, FullJidSubs} = get_subscriptions(Nidx, SubKey),
- {Affiliation, BareJidSubs++FullJidSubs}.
+ GJ = encode_jid(GenKey),
+ SJ = encode_jid(SubKey),
+ case catch
+ ejabberd_sql:sql_query_t(
+ ?SQL("select jid = %(GJ)s as @(G)d, @(affiliation)s, @(subscriptions)s from "
+ " pubsub_state where nodeid=%(Nidx)d and jid in (%(GJ)s, %(SJ)s)"))
+ of
+ {selected, Res} ->
+ lists:foldr(
+ fun({1, A, S}, {_, Subs}) ->
+ {decode_affiliation(A), Subs ++ decode_subscriptions(S)};
+ ({_, _, S}, {Aff, Subs}) ->
+ {Aff, Subs ++ decode_subscriptions(S)}
+ end, {none, []}, Res);
+ _ ->
+ {none, []}
+ end.
update_affiliation(Nidx, JID, Affiliation) ->
J = encode_jid(JID),