Skip to content

Commit

Permalink
Pass binary into mongoose_rdbms:prepare/4 from mam modules
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Dec 14, 2020
1 parent 5a1ca51 commit 7f01379
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
27 changes: 12 additions & 15 deletions src/mam/mod_mam_muc_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ stop_hooks(Host) ->
register_prepared_queries() ->
prepare_insert(insert_mam_muc_message, 1),
mongoose_rdbms:prepare(mam_muc_archive_remove, mam_muc_message, [room_id],
[<<"DELETE FROM mam_muc_message "
"WHERE room_id = ?">>]),
<<"DELETE FROM mam_muc_message "
"WHERE room_id = ?">>),
mongoose_rdbms:prepare(mam_muc_make_tombstone, mam_muc_message, [message, room_id, id],
[<<"UPDATE mam_muc_message SET message = ?, search_body = '' "
"WHERE room_id = ? AND id = ?">>]),
<<"UPDATE mam_muc_message SET message = ?, search_body = '' "
"WHERE room_id = ? AND id = ?">>),
{LimitSQL, LimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(1),
mongoose_rdbms:prepare(mam_muc_select_messages_to_retract, mam_muc_message,
[room_id, sender_id, origin_id],
[<<"SELECT ", LimitMSSQL/binary,
" id, message FROM mam_muc_message"
" WHERE room_id = ? AND sender_id = ? "
" AND origin_id = ?"
" ORDER BY id DESC ", LimitSQL/binary>>]),
<<"SELECT ", LimitMSSQL/binary,
" id, message FROM mam_muc_message"
" WHERE room_id = ? AND sender_id = ? "
" AND origin_id = ?"
" ORDER BY id DESC ", LimitSQL/binary>>),
mongoose_rdbms:prepare(mam_muc_extract_gdpr_messages, mam_muc_message, [sender_id],
[<<"SELECT id, message FROM mam_muc_message "
" WHERE sender_id = ? ORDER BY id">>]).
<<"SELECT id, message FROM mam_muc_message "
" WHERE sender_id = ? ORDER BY id">>).

%% ----------------------------------------------------------------------
%% Declarative logic
Expand Down Expand Up @@ -287,12 +287,9 @@ prepare_insert(Name, NumRows) ->
ArcID :: mod_mam:archive_id(),
ArcJID :: jid:jid()) -> mongoose_acc:t().
remove_archive(Acc, Host, ArcID, _ArcJID) ->
remove_archive(Host, ArcID),
mongoose_rdbms:execute_successfully(Host, mam_muc_archive_remove, [ArcID]),
Acc.

remove_archive(Host, ArcID) ->
mongoose_rdbms:execute_successfully(Host, mam_muc_archive_remove, [ArcID]).

%% GDPR logic
extract_gdpr_messages(Host, SenderID) ->
mongoose_rdbms:execute_successfully(Host, mam_muc_extract_gdpr_messages, [SenderID]).
Expand Down
23 changes: 10 additions & 13 deletions src/mam/mod_mam_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ stop_hooks(Host) ->
register_prepared_queries() ->
prepare_insert(insert_mam_message, 1),
mongoose_rdbms:prepare(mam_archive_remove, mam_message, [user_id],
[<<"DELETE FROM mam_message "
"WHERE user_id = ?">>]),
<<"DELETE FROM mam_message "
"WHERE user_id = ?">>),
mongoose_rdbms:prepare(mam_make_tombstone, mam_message, [message, user_id, id],
[<<"UPDATE mam_message SET message = ?, search_body = '' "
"WHERE user_id = ? AND id = ?">>]),
<<"UPDATE mam_message SET message = ?, search_body = '' "
"WHERE user_id = ? AND id = ?">>),
{LimitSQL, LimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(1),
mongoose_rdbms:prepare(mam_select_messages_to_retract, mam_message,
[user_id, remote_bare_jid, origin_id, direction],
[<<"SELECT ", LimitMSSQL/binary,
" id, message FROM mam_message"
" WHERE user_id = ? AND remote_bare_jid = ? "
" AND origin_id = ? AND direction = ?"
" ORDER BY id DESC ", LimitSQL/binary>>]).
<<"SELECT ", LimitMSSQL/binary,
" id, message FROM mam_message"
" WHERE user_id = ? AND remote_bare_jid = ? "
" AND origin_id = ? AND direction = ?"
" ORDER BY id DESC ", LimitSQL/binary>>).

%% ----------------------------------------------------------------------
%% Declarative logic
Expand Down Expand Up @@ -311,12 +311,9 @@ prepare_insert(Name, NumRows) ->
ArcID :: mod_mam:archive_id(),
RoomJID :: jid:jid()) -> mongoose_acc:t().
remove_archive(Acc, Host, ArcID, _ArcJID) ->
remove_archive(Host, ArcID),
mongoose_rdbms:execute_successfully(Host, mam_archive_remove, [ArcID]),
Acc.

remove_archive(Host, ArcID) ->
mongoose_rdbms:execute_successfully(Host, mam_archive_remove, [ArcID]).

%% GDPR logic
extract_gdpr_messages(Env, ArcID) ->
Filters = [{equal, user_id, ArcID}],
Expand Down
4 changes: 2 additions & 2 deletions src/mam/mod_mam_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ has_chat_marker(Packet) ->

get_retract_id(true = _Enabled, Packet) ->
get_retract_id(Packet);
get_retract_id(false, Packet) ->
get_retract_id(false, _Packet) ->
none.

get_retract_id(Packet) ->
Expand Down Expand Up @@ -770,7 +770,7 @@ packet_to_search_body(Module, Host, Packet) ->
packet_to_search_body(true, Packet) ->
BodyValue = exml_query:path(Packet, [{element, <<"body">>}, cdata], <<>>),
mod_mam_utils:normalize_search_text(BodyValue, <<" ">>);
packet_to_search_body(false, Packet) ->
packet_to_search_body(false, _Packet) ->
<<>>.

-spec has_full_text_search(Module :: mod_mam | mod_mam_muc, Host :: jid:server()) -> boolean().
Expand Down

0 comments on commit 7f01379

Please sign in to comment.