-
Notifications
You must be signed in to change notification settings - Fork 911
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
listpays: sort output payments #4518
Conversation
cbd920a
to
5eb90da
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.
I have only a small curiosity and I would like to know more about that.
I'm not able to catch what Is the reason to collect the result from the database and only after sort it, instant to ask the database the list of payment sorted.
The only motivation that I have in mind is that the databases used from c-lightning use a different dialect, but I'm not able to prove that because the ORDER BY
should be a basic construct of the SQL language
OK, this is a great start! Your code is really nice. Some feedback:
Thanks! |
Thanks for the note @vincenzopalazzo @rustyrussell. I realised that after making this PR (which is why I ended up marking it as a draft PR). I'll make both the noted changes soon. |
5eb90da
to
1459ab0
Compare
@rustyrussell @vincenzopalazzo ready for review. |
@@ -3143,7 +3143,8 @@ wallet_payment_list(const tal_t *ctx, | |||
", partid" | |||
", local_offer_id" | |||
" FROM payments" | |||
" WHERE payment_hash = ?;")); | |||
" WHERE payment_hash = ?" | |||
" ORDER BY id;")); |
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 you think that sort by timestamp
it is a good idea here?
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.
id is the order it was placed in the db, which is probably right here.
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.
utack 1459ab0
With two small nit to me, but @rustyrussell can undo my comments if they are wrong.
- If you sort (ORDER by timestamp ASC | DESC) by timestamp you can avoid the sorting operation, this moves the work from lightning code to database code, and the database can (or should/may) have better performance in sorting things. In addition, this change simplifies the code in the pay plugin.
- Use the query to sort the element you can avoid using the additional array, but it is in contrast with point 4 of Rusty's comment, so in this case, I can missing some things.
PS: I would like to have an additional test in test_pay that makes sure that the array is really sorted, to avoid crazy debugging in some case in the future.
Unfortunately,
More tests would always be nice, of course! I will have a go at writing one, since this needs a trivial rebase anyway... |
Changelog-Changed: JSON: `listsendpays` output is now ordered by `id`.
Changelog-Changed: `listpays` output is now ordered by the `created_at` timestamp.
Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
1459ab0
to
0d62227
Compare
@nalinbhardwaj Sorry for the delay. Did a trivial rebase to fix the merge conflict with db files, and added tests and docs. What do you think? |
@rustyrussell Looks great! Thanks for the rebase and the doc+tests updates. Let me know if there's anything else I missed before. |
ACK 0d62227 |
Fixes #4481.