Skip to content

Commit 78771d1

Browse files
authored
Merge pull request #4552 from esl/cached-affs-in-api
Use cached affiliations in MUC Light API
2 parents 0f2b78f + 6e5ed81 commit 78771d1

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

big_tests/tests/graphql_muc_light_SUITE.erl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
get_coercion_err_msg/1, make_creds/1, get_unauthorized/1,
1010
get_err_code/1, get_not_loaded/1]).
1111

12-
-import(config_parser_helper, [mod_config/2]).
12+
-import(config_parser_helper, [config/2]).
1313

1414
-include_lib("common_test/include/ct.hrl").
1515
-include_lib("jid/include/jid.hrl").
@@ -209,12 +209,15 @@ end_per_suite(Config) ->
209209
escalus:end_per_suite(Config).
210210

211211
required_modules(_) ->
212-
Backend = mongoose_helper:mnesia_or_rdbms_backend(),
213-
MucLightOpts = mod_config(mod_muc_light, #{backend => Backend,
214-
rooms_in_rosters => true,
215-
config_schema => custom_schema()}),
212+
MucLightOpts = config([modules, mod_muc_light], muc_light_opts()),
216213
[{mod_muc_light, MucLightOpts}].
217214

215+
muc_light_opts() ->
216+
#{backend => mongoose_helper:mnesia_or_rdbms_backend(),
217+
cache_affs => #{},
218+
rooms_in_rosters => true,
219+
config_schema => custom_schema()}.
220+
218221
custom_schema() ->
219222
%% Should be sorted
220223
[{<<"background">>, <<>>, background, binary},

src/muc_light/mod_muc_light.erl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
room_exists/3,
5656
can_access_identity/3]).
5757

58-
-export([get_acc_room_affiliations/2]).
58+
-export([get_room_affiliations/2,
59+
get_acc_room_affiliations/2]).
5960

6061
%% For propEr
6162
-export([apply_rsm/3]).
@@ -559,6 +560,15 @@ acc_room_affiliations(Acc1, #{room := RoomJid}, _Extra) ->
559560
room_exists(_, #{room := RoomJid}, #{host_type := HostType}) ->
560561
{ok, mod_muc_light_db_backend:room_exists(HostType, jid:to_lus(RoomJid))}.
561562

563+
-spec get_room_affiliations(mongooseim:host_type(), jid:jid()) ->
564+
versioned_affs() | {error, not_exists}.
565+
get_room_affiliations(HostType, RoomJid) ->
566+
Acc1 = mongoose_acc:new(#{location => ?LOCATION,
567+
lserver => RoomJid#jid.lserver,
568+
host_type => HostType}),
569+
Acc2 = mongoose_hooks:acc_room_affiliations(Acc1, RoomJid),
570+
get_room_affs_from_acc(Acc2, RoomJid).
571+
562572
-spec get_acc_room_affiliations(mongoose_acc:t(), jid:jid()) ->
563573
{mongoose_acc:t(), versioned_affs() | {error, not_exists}}.
564574
get_acc_room_affiliations(Acc1, RoomJid) ->

src/muc_light/mod_muc_light_api.erl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ return_info(#{room := RoomJID, aff_users := AffUsers, options := Config}) ->
319319
{ok, make_room(jid:to_binary(RoomJID), Config, AffUsers)}.
320320

321321
do_get_room_aff(M = #{room := RoomJID, muc_host_type := HostType}) ->
322-
case mod_muc_light_db_backend:get_aff_users(HostType, jid:to_lus(RoomJID)) of
322+
case mod_muc_light:get_room_affiliations(HostType, RoomJID) of
323323
{ok, AffUsers, _Version} ->
324324
M#{aff_users => AffUsers};
325325
{error, not_exists} ->
@@ -368,10 +368,9 @@ make_room_config(Options) ->
368368
-spec get_room_user_aff(mongooseim:host_type(), jid:jid(), jid:jid()) ->
369369
{ok, aff()} | {error, room_not_found}.
370370
get_room_user_aff(HostType, RoomJID, UserJID) ->
371-
RoomUS = jid:to_lus(RoomJID),
372-
UserUS = jid:to_lus(UserJID),
373-
case mod_muc_light_db_backend:get_aff_users(HostType, RoomUS) of
371+
case mod_muc_light:get_room_affiliations(HostType, RoomJID) of
374372
{ok, Affs, _Version} ->
373+
UserUS = jid:to_lus(UserJID),
375374
{ok, get_aff(UserUS, Affs)};
376375
{error, not_exists} ->
377376
{error, room_not_found}

0 commit comments

Comments
 (0)