Skip to content

Commit

Permalink
Fail to start on MSSQL with delete_domain_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 10, 2023
1 parent 42a246d commit e658b06
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
15 changes: 9 additions & 6 deletions src/inbox/mod_inbox_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) ->
mongoose_rdbms:prepare(
inbox_delete_domain, inbox, [lserver], <<"DELETE FROM inbox WHERE lserver = ?">>);
prepare_remove_domain(#{delete_domain_limit := Limit}) ->
{MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit),
ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" lserver, luser, remote_bare_jid FROM inbox",
" WHERE lserver = ? ", MaybeLimitSQL/binary, ") AS T)">>,
LimitSQL = case mongoose_rdbms:db_type() of
mssql -> throw(delete_domain_limit_not_supported_for_mssql);
_ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit),
MaybeLimitSQL
end,
ServerTable = <<"(SELECT * FROM ",
"(SELECT lserver, luser, remote_bare_jid FROM inbox",
" WHERE lserver = ? ", LimitSQL/binary, ") AS T)">>,
mongoose_rdbms:prepare(
inbox_incr_delete_domain, inbox, [lserver],
<<"DELETE FROM inbox WHERE (lserver, luser, remote_bare_jid) IN ",
ServerTable/binary>>).
<<"DELETE FROM inbox WHERE (lserver, luser, remote_bare_jid) IN ", ServerTable/binary>>).

-spec get_inbox(HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
Expand Down
25 changes: 13 additions & 12 deletions src/mam/mod_mam_muc_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,21 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) ->
mongoose_rdbms:prepare(mam_muc_remove_domain_users, mam_server_user, [server],
<<"DELETE FROM mam_server_user WHERE server = ? ">>);
prepare_remove_domain(#{delete_domain_limit := Limit}) ->
{MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit),
IdTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" msg.room_id, msg.id FROM mam_muc_message msg",
" INNER JOIN mam_server_user msu ON msu.id=msg.room_id",
" WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>,
LimitSQL = case mongoose_rdbms:db_type() of
mssql -> throw(delete_domain_limit_not_supported_for_mssql);
_ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit),
MaybeLimitSQL
end,
IdTable = <<"(SELECT * FROM ",
"(SELECT msg.room_id, msg.id FROM mam_muc_message msg",
" INNER JOIN mam_server_user msu ON msu.id=msg.room_id",
" WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>,
mongoose_rdbms:prepare(mam_muc_incr_remove_domain, mam_muc_message, ['mam_server_user.server'],
<<"DELETE FROM mam_muc_message "
"WHERE (room_id, id) IN ", IdTable/binary>>),

ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" id FROM mam_server_user WHERE server = ? ", MaybeLimitSQL/binary, ") as t)">>,
<<"DELETE FROM mam_muc_message WHERE (room_id, id) IN ", IdTable/binary>>),
ServerTable = <<"(SELECT * FROM",
"(SELECT id FROM mam_server_user WHERE server = ? ", LimitSQL/binary, ") as t)">>,
mongoose_rdbms:prepare(mam_muc_incr_remove_domain_users, mam_server_user, [server],
<<"DELETE ", MaybeLimitMSSQL/binary,
" FROM mam_server_user WHERE id IN ", ServerTable/binary>>).
<<"DELETE FROM mam_server_user WHERE id IN ", ServerTable/binary>>).

%% ----------------------------------------------------------------------
%% Declarative logic
Expand Down
34 changes: 17 additions & 17 deletions src/mam/mod_mam_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,28 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) ->
mongoose_rdbms:prepare(mam_remove_domain_users, mam_server_user, [server],
<<"DELETE FROM mam_server_user WHERE server = ?">>);
prepare_remove_domain(#{delete_domain_limit := Limit}) ->
{MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit),
IdTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" msg.user_id, msg.id FROM mam_message msg",
" INNER JOIN mam_server_user msu ON msu.id=msg.user_id",
" WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>,
LimitSQL = case mongoose_rdbms:db_type() of
mssql -> throw(delete_domain_limit_not_supported_for_mssql);
_ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit),
MaybeLimitSQL
end,
IdTable = <<"(SELECT * FROM ",
"(SELECT msg.user_id, msg.id FROM mam_message msg",
" INNER JOIN mam_server_user msu ON msu.id=msg.user_id",
" WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>,
mongoose_rdbms:prepare(mam_incr_remove_domain, mam_message, ['mam_server_user.server'],
<<"DELETE FROM mam_message "
"WHERE (user_id, id) IN ", IdTable/binary>>),

CfgTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" cfg.user_id, cfg.remote_jid FROM mam_config cfg",
" INNER JOIN mam_server_user msu ON msu.id=cfg.user_id",
" WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>,
<<"DELETE FROM mam_message WHERE (user_id, id) IN ", IdTable/binary>>),
CfgTable = <<"(SELECT * FROM ",
"(SELECT cfg.user_id, cfg.remote_jid FROM mam_config cfg",
" INNER JOIN mam_server_user msu ON msu.id=cfg.user_id",
" WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>,
mongoose_rdbms:prepare(mam_incr_remove_domain_prefs, mam_config, ['mam_server_user.server'],
<<"DELETE FROM mam_config "
"WHERE (user_id, remote_jid) IN ", CfgTable/binary>>),

ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary,
" id FROM mam_server_user WHERE server = ? ", MaybeLimitSQL/binary, ") as t)">>,
ServerTable = <<"(SELECT * FROM ",
"(SELECT id FROM mam_server_user WHERE server = ? ", LimitSQL/binary, ") as t)">>,
mongoose_rdbms:prepare(mam_incr_remove_domain_users, mam_server_user, [server],
<<"DELETE ", MaybeLimitMSSQL/binary,
" FROM mam_server_user WHERE id IN ", ServerTable/binary>>).
<<"DELETE FROM mam_server_user WHERE id IN ", ServerTable/binary>>).


%% ----------------------------------------------------------------------
Expand Down

0 comments on commit e658b06

Please sign in to comment.