Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use map for mod_mam:message_row() #3093

Merged
merged 7 commits into from
Apr 27, 2021
Merged

Conversation

arcusfelis
Copy link
Contributor

@arcusfelis arcusfelis commented Apr 22, 2021

This PR addresses "what if we use map, will tests still pass?"

Proposed changes include:

  • map
  • Allow to override mod_mam_utils:send_message/4 callback.
  • Pass caller_jid into lookup_messages hook as a part of params (useful for MUC MAM).

As a dev, I want to extract some extra fields from MAM (or during MAM lookup).
I am currently only allowed to return message-id, source-jid and stanza packet. But sometimes I need to return more fields, so I can format them later (to build a proper forwarded message). Maps allows to attach some meta info to each message.

Also, it's really hard to track what is what in 3 fields tuple :trollface:

@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #3093 (9e4832e) into master (1436629) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3093      +/-   ##
==========================================
- Coverage   79.08%   79.03%   -0.06%     
==========================================
  Files         386      387       +1     
  Lines       31829    31838       +9     
==========================================
- Hits        25172    25163       -9     
- Misses       6657     6675      +18     
Impacted Files Coverage Δ
src/mam/mam_iq.erl 71.42% <ø> (ø)
src/mam/mod_mam_meta.erl 94.68% <ø> (ø)
src/mam/mod_mam_rdbms_arch.erl 49.47% <ø> (ø)
src/mam/mod_mam_utils.erl 89.56% <ø> (ø)
..._client_api/mongoose_client_api_rooms_messages.erl 96.05% <ø> (ø)
src/mam/mam_decoder.erl 100.00% <100.00%> (ø)
src/mam/mam_lookup.erl 96.15% <100.00%> (ø)
src/mam/mam_send_message.erl 100.00% <100.00%> (ø)
src/mam/mod_mam.erl 89.44% <100.00%> (+0.19%) ⬆️
src/mam/mod_mam_cassandra_arch.erl 84.68% <100.00%> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1436629...9e4832e. Read the comment docs.

@arcusfelis arcusfelis force-pushed the mu-mam-message-row-is-map branch 2 times, most recently from fe97255 to 2787246 Compare April 23, 2021 15:00
@arcusfelis arcusfelis changed the title PoC Use map for mod_mam:message_row() Use map for mod_mam:message_row() Apr 26, 2021
Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very very good, just a few comments in the tests 😄

big_tests/tests/mam_send_message_SUITE.erl Outdated Show resolved Hide resolved
big_tests/tests/mam_send_message_SUITE.erl Outdated Show resolved Hide resolved
Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally love it. It has a theoretical impact on performance, but it's probably just theoretical. This is one of the cases where flexibility outweighs those tiny nanoseconds. And this is a very useful one to me 🙂

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have a few comments and Elvis has two that I agree with:

mod_mam.erl   460   1 warning  invalid_dynamic_call Remove the dynamic function call on line 460. Only modules that define callbacks should make dynamic calls. (lsp)
mod_mam.erl   617   1 warning  line_length Line 617 is too long: message_row_to_xml(MamNs, #{id := MessID, jid := SrcJID, packet := Packet}, QueryID, SetClientNs)  ->. (lsp)

@@ -158,7 +158,8 @@ decode_rows(MessageRows, Env) ->
[decode_row(Row, Env) || Row <- MessageRows].

%% First element of the tuple is decoded message ID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no tuple now, please amend this comment.

@@ -119,7 +118,7 @@

-type borders() :: #mam_borders{}.

-type message_row() :: {message_id(), jid:jid(), exml:element()}.
-type message_row() :: #{id => message_id(), jid => jid:jid(), packet => exml:element()}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they optional? Could we make the keys mandatory in this type?

Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

@NelsonVides NelsonVides merged commit 9330d02 into master Apr 27, 2021
@NelsonVides NelsonVides deleted the mu-mam-message-row-is-map branch April 27, 2021 15:01
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit late, but it looks great, thanks for the extra work to address the comments!

@Premwoik Premwoik added this to the 5.0.0 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants