-
Notifications
You must be signed in to change notification settings - Fork 59
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
refactor: move exit info related functions to smaller responsibility module #1503
refactor: move exit info related functions to smaller responsibility module #1503
Conversation
dce58bb
to
2e681aa
Compare
5a8c49e
to
2156ff2
Compare
spent_blknum: 2, | ||
block_hashes: 2, | ||
child_top_block_number: 1 | ||
child_top_block_number: 1, | ||
get_single_value: 2 |
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.
Did not add get/3
and get_all_by_type/2
as optional as it is used in the implementation of PaymentExitInfo
455cf87
to
9d23ad3
Compare
9d23ad3
to
e5aac6e
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.
Approving with a comment on some logs not being moved to the new functions :)
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.
Wait, I didn't understand what we're trying to fix here...
9f58834
to
6180a5e
Compare
|
||
def exit_infos(utxo_pos_list, server_name \\ @server_name) | ||
when is_list(utxo_pos_list) do | ||
DB.get(:exit_info, utxo_pos_list, @ten_seconds, server_name) |
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 am not 100% sure on the data size yet. 10 sec might be premature large?
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.
Can you make it optional in DB.get
with 5 seconds (default GenServer call's timeout)
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.
okay. To introduce multiple optional args, I have to use opts \\ []
instead of timeout \\ 5000, server \\ @server_name
to allow optional args combination in timeout
and server
. (unless there is better way of doing this?)
apps/omg_db/lib/db.ex
Outdated
This is generic DB function that can get the specific data of a specific type. | ||
If it is a single value data, use get_single_value/1 instead. | ||
""" | ||
def get(type, specific_keys, timeout), do: driver().get(type, specific_keys, timeout) |
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 want to name this get_multi
instead?
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.
👍 yes, be specific!
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.
rename the function to batch_get
25996de
to
e0c44ea
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! (just minors left)
|
||
def exit_infos(utxo_pos_list, server_name \\ @server_name) | ||
when is_list(utxo_pos_list) do | ||
DB.get(:exit_info, utxo_pos_list, @ten_seconds, server_name) |
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.
Can you make it optional in DB.get
with 5 seconds (default GenServer call's timeout)
apps/omg_db/lib/db.ex
Outdated
This is generic DB function that can get the specific data of a specific type. | ||
If it is a single value data, use get_single_value/1 instead. | ||
""" | ||
def get(type, specific_keys, timeout), do: driver().get(type, specific_keys, timeout) |
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.
👍 yes, be specific!
So instead of calling the rock db implementation, it calls the DB interface. This removes the need of having the a PaymentExitInfo behaviour.
Receiving list of specific keys is more useful :) Also make changes to the PaymentExitInfo apis accordingly
Use keyword list to support multi optional args. (timeout and server)
c761fc5
to
6593d83
Compare
📋 ref https://github.com/omisego/new-tx-type-poc/issues/9
Overview
Move
exit_info
related DB access toPaymentExitInfo
module instead. The motivation is to make the code easier to scale when we are adding new tx types. We will write newPaymentV2ExitInfo
for example when we extend to payment v2.First step to break the big DB module into smaller pieces!
Changes
OMG.DB
toOMG.DB.Models.PaymentExitInfo
get
andget_all_by_type
fromOMG.DB
for the db models module to call and simplify the code.type
param fromdecode_value
anddecode_values
method ofRocksDB.Core
.Question
Can we remove one of
OMG.DBTest
andOMG.RocksDBTest
? They are testing same thing now?Testing
get/2, 3
andget_all_by_type/1, 2