-
Notifications
You must be signed in to change notification settings - Fork 426
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
Prepared queries for MAM #2961
Prepared queries for MAM #2961
Conversation
Codecov Report
@@ Coverage Diff @@
## mu-prepared-queries #2961 +/- ##
=======================================================
+ Coverage 79.10% 79.39% +0.28%
=======================================================
Files 377 382 +5
Lines 32846 32810 -36
=======================================================
+ Hits 25982 26048 +66
+ Misses 6864 6762 -102
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements.
I added some comments and I think a few of them should be addressed to make the code even better.
@@ -28,8 +28,13 @@ | |||
|
|||
-export([get_db_type/0, | |||
begin_trans/0, | |||
get_db_specific_limits/0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unused, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_db_specific_limits/0
is used now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments. There is a lot of good changes, thanks for that.
However, I think the PR itself became a bit too big, I hoped we could divide the work as agreed before.
Anyway, the only serious concerns are about the untested lines of code.
include/mongoose_mam.hrl
Outdated
@@ -0,0 +1,2 @@ | |||
-record(db_mapping, {column :: atom(), param :: atom(), format :: atom()}). | |||
-record(lookup_field, {op :: atom(), column :: atom(), param :: atom(), required :: atom(), value_maker :: atom()}). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long, just put each field in a separate line.
There are more lines longer than 100 characters in this PR. I am not adding any comments to the rest them, but I think it's good to change them stay within this limit - inaka/elvis recommends that and I think it's a reasonable value.
Btw, is required
boolean()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required :: true | undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not true | false
?
src/mam/mam_decoder.erl
Outdated
decode_row({ExtMessID, ExtSrcJID, ExtData}, Env) -> | ||
MessID = mongoose_rdbms:result_to_integer(ExtMessID), | ||
SrcJID = decode_jid(ExtSrcJID, Env), | ||
Packet = decode_packet(ExtData, Env), | ||
{MessID, SrcJID, Packet}. | ||
|
||
decode_muc_row({ExtMessID, Nick, ExtData}, Env = #{archive_jid := RoomJID}) -> | ||
MessID = mongoose_rdbms:result_to_integer(ExtMessID), | ||
SrcJID = jid:replace_resource(RoomJID, Nick), | ||
Packet = decode_packet(ExtData, Env), | ||
{MessID, SrcJID, Packet}. | ||
|
||
decode_muc_gdpr_row({ExtMessID, ExtData}, Env) -> | ||
Packet = decode_packet(ExtData, Env), | ||
{ExtMessID, Packet}. | ||
|
||
decode_retraction_info(_Env, []) -> skip; | ||
decode_retraction_info(Env, [{ResMessID, Data}]) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add type specs for exported functions? Or are you planning to do that later?
src/mam/mam_lookup.erl
Outdated
|
||
%% Private logic below | ||
|
||
%% There is no optimizations for these queries yet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%% There is no optimizations for these queries yet: | |
%% There are no optimizations for these queries yet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, skipped this. Would add that after the final review ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
@@ -28,8 +28,13 @@ | |||
|
|||
-export([get_db_type/0, | |||
begin_trans/0, | |||
get_db_specific_limits/0, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
f819c09
to
f8f3b84
Compare
@arcusfelis I think we need to rebase this branch - it shows many more commits than it should which makes it hard to review. |
f8f3b84
to
72d5c9a
Compare
72d5c9a
to
cc3b30f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the minio
fix from the PR? The rest look really good, I only have a few concerns, once these few are addressed it can be merged.
src/mam/mam_decoder.erl
Outdated
|
||
-spec unescape_binary(binary(), env_vars()) -> binary(). | ||
unescape_binary(Bin, #{host := Host}) -> | ||
%% Funny, rdbms ignores this Host variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: It's good to have this remark, but maybe remove the word 'funny'? It just does not seem right for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the whole comment.
src/mam/mam_lookup_sql.erl
Outdated
What = #{what => mam_lookup_failed, statement => StmtName, | ||
sql_query => lookup_sql_binary(QueryType, Table, Env, Filters, Order, OffsetLimit), | ||
reason => Error, host => Host}, | ||
?LOG_ERROR(What), | ||
error(What) | ||
catch error:Error:Stacktrace -> | ||
What = #{what => mam_lookup_failed, statement => StmtName, | ||
sql_query => lookup_sql_binary(QueryType, Table, Env, Filters, Order, OffsetLimit), | ||
stacktrace => Stacktrace, reason => Error, host => Host}, | ||
?LOG_ERROR(What), | ||
erlang:raise(error, Error, Stacktrace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worries me a bit that these lines are not tested, but I understand that we only check the happy path in tests. Did you check both error cases manually? I think it's necessary here, especially given the recent formatter crashes - we often have errors in error handling (sic!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason why it's here is that it's good to see an SQL query string when something fails.
But it's pretty generic code. And we also have mod_mam_utils:success_sql_query/?
.
So, I've created mongoose_rdbms:execute_successfully/3
for all these cases (and we don't have error handling in MAM anymore, that's good)
src/mam/mam_lookup_sql.erl
Outdated
|
||
filters_to_sql(Filters) -> | ||
SQLs = [filter_to_sql(Filter) || Filter <- Filters], | ||
case skip_undefined(SQLs) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to do this? It looks like we do not have undefined
in the list. Btw, I prefer code without temporary undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
cc3b30f
to
5bef9cc
Compare
Address review comments
So, we can more easily print it Also, ets-lookup logic would run a bit faster for big iolists
f73c84d
to
031e841
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, great work 👍
…- final commit So, we can more easily print it Also, ets-lookup logic would run a bit faster for big iolists
Store statement as binary in prepared_statements ETS table So, we can more easily print it Also, ets-lookup logic would run a bit faster for big iolists
This PR is rebased version of #2958
Proposed changes include: