From 48a5bba95cd685e42844b995598e474a03f58a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 21 Oct 2022 09:59:22 +0200 Subject: [PATCH] --amend --- big_tests/tests/graphql_stanza_SUITE.erl | 10 +++++++--- src/graphql/mongoose_graphql_stanza_helper.erl | 5 ++--- src/mongoose_stanza_api.erl | 12 +++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/big_tests/tests/graphql_stanza_SUITE.erl b/big_tests/tests/graphql_stanza_SUITE.erl index 5850bd73e7..713d06b5ff 100644 --- a/big_tests/tests/graphql_stanza_SUITE.erl +++ b/big_tests/tests/graphql_stanza_SUITE.erl @@ -1,5 +1,6 @@ -module(graphql_stanza_SUITE). +-include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("exml/include/exml.hrl"). @@ -111,9 +112,11 @@ init_mam(Config) when is_list(Config) -> disabled -> Config; Backend -> - Mods = [{mod_mam, mam_helper:config_opts(#{backend => Backend, pm => #{}})}], + MAMOpts = #{max_result_limit := MaxResultLimit} = + mam_helper:config_opts(#{backend => Backend, pm => #{}}), + Mods = [{mod_mam, MAMOpts}], dynamic_modules:ensure_modules(domain_helper:host_type(), Mods), - [{has_mam, true}|Config] + [{has_mam, true}, {max_result_limit, MaxResultLimit}|Config] end; init_mam(Other) -> Other. @@ -407,7 +410,8 @@ admin_get_last_messages_limit_enforced_story(Config, Alice, Bob) -> Caller = escalus_client:full_jid(Alice), Res = get_last_messages(Caller, null, 1000, null, Config), %% The actual limit is returned - #{<<"stanzas">> := [M1], <<"limit">> := 500} = + MaxResultLimit = ?config(max_result_limit, Config), + #{<<"stanzas">> := [M1], <<"limit">> := MaxResultLimit} = get_ok_value([data, stanza, getLastMessages], Res), check_stanza_map(M1, Alice). diff --git a/src/graphql/mongoose_graphql_stanza_helper.erl b/src/graphql/mongoose_graphql_stanza_helper.erl index fb33a14e12..87ccececbc 100644 --- a/src/graphql/mongoose_graphql_stanza_helper.erl +++ b/src/graphql/mongoose_graphql_stanza_helper.erl @@ -10,10 +10,9 @@ Before :: null | mod_mam:unix_timestamp(), boolean()) -> {ok, map()} | {unknown_user, iodata()}. get_last_messages(Caller, Limit, With, Before, CheckUser) -> - Limit2 = min(500, Limit), case mongoose_stanza_api:lookup_recent_messages( - Caller, null_to_undefined(With), null_to_undefined(Before), Limit2, CheckUser) of - {ok, Rows} -> + Caller, null_to_undefined(With), null_to_undefined(Before), Limit, CheckUser) of + {ok, {Rows, Limit2}} -> Maps = lists:map(fun row_to_map/1, Rows), {ok, #{<<"stanzas">> => Maps, <<"limit">> => Limit2}}; Error -> diff --git a/src/mongoose_stanza_api.erl b/src/mongoose_stanza_api.erl index 1f3bf22cd3..bf3e5deb7b 100644 --- a/src/mongoose_stanza_api.erl +++ b/src/mongoose_stanza_api.erl @@ -35,7 +35,7 @@ send_stanza(User, Stanza) -> -spec lookup_recent_messages(User :: jid:jid(), With :: jid:jid() | undefined, Before :: mod_mam:unix_timestamp() | undefined, % microseconds Limit :: non_neg_integer(), CheckUser :: boolean()) -> - {unknown_user, iodata()} | {ok, [mod_mam:message_row()]}. + {unknown_user, iodata()} | {ok, {[mod_mam:message_row()], non_neg_integer()}}. lookup_recent_messages(User, With, Before, Limit, CheckUser) -> M = #{user => User, with => With, before => Before, limit => Limit, check_user => CheckUser}, fold(M, [fun get_host_type/1, fun check_user/1, fun check_before/1, fun lookup_messages/1]). @@ -115,6 +115,8 @@ check_before(M) -> lookup_messages(#{user := UserJid, with := WithJid, before := Before, limit := Limit, host_type := HostType}) -> #jid{luser = LUser, lserver = LServer} = UserJid, + MaxResultLimit = mod_mam_params:max_result_limit(mod_mam_pm, HostType), + Limit2 = min(Limit, MaxResultLimit), Params = #{archive_id => mod_mam_pm:archive_id(LServer, LUser), owner_jid => UserJid, borders => undefined, @@ -124,12 +126,12 @@ lookup_messages(#{user := UserJid, with := WithJid, before := Before, limit := L now => os:system_time(microsecond), with_jid => WithJid, search_text => undefined, - page_size => Limit, + page_size => Limit2, limit_passed => false, - max_result_limit => 1, + max_result_limit => MaxResultLimit, is_simple => true}, - {ok, {_, _, L}} = mod_mam_pm:lookup_messages(HostType, Params), - {ok, L}. + {ok, {_, _, Rows}} = mod_mam_pm:lookup_messages(HostType, Params), + {ok, {Rows, Limit2}}. fold({_, _} = Result, _) -> Result;