-
Notifications
You must be signed in to change notification settings - Fork 116
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
Implement sorting functionality and add total_supply for Universe Ass… #485
Conversation
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 a lot for the PR!
Looks pretty good, main comments are around code style/optimizations.
tapdb/sqlc/queries/universe.sql
Outdated
WHEN sqlc.narg('sort_by') = 'genesis_height' THEN asset_info.genesis_height | ||
ELSE NULL | ||
END | ||
CASE WHEN sqlc.narg('sort_by') = 'asset_id' AND sqlc.narg('sort_direction') = 0 THEN asset_info.asset_id END ASC, |
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 we unify the formatting here a bit so it's easier to read on narrow terminals? We aim at ~80 characters for those who like to have many rows of vim open.
Also, the ASC is kind of superfluous as it's the default.
My suggestion:
ORDER BY
CASE WHEN sqlc.narg('sort_by') = 'asset_id' AND sqlc.narg('sort_direction') = 0 THEN
asset_info.asset_id END,
CASE WHEN sqlc.narg('sort_by') = 'asset_id' AND sqlc.narg('sort_direction') = 1 THEN
asset_info.asset_id END DESC ,
CASE WHEN sqlc.narg('sort_by') = 'asset_name' AND sqlc.narg('sort_direction') = 0 THEN
asset_info.asset_name END,
CASE WHEN sqlc.narg('sort_by') = 'asset_name' AND sqlc.narg('sort_direction') = 1 THEN
asset_info.asset_name END DESC ,
CASE WHEN sqlc.narg('sort_by') = 'asset_type' AND sqlc.narg('sort_direction') = 0 THEN
asset_info.asset_type END,
CASE WHEN sqlc.narg('sort_by') = 'asset_type' AND sqlc.narg('sort_direction') = 1 THEN
asset_info.asset_type END DESC,
CASE WHEN sqlc.narg('sort_by') = 'total_syncs' AND sqlc.narg('sort_direction') = 0 THEN
universe_stats.total_asset_syncs END,
CASE WHEN sqlc.narg('sort_by') = 'total_syncs' AND sqlc.narg('sort_direction') = 1 THEN
universe_stats.total_asset_syncs END DESC,
CASE WHEN sqlc.narg('sort_by') = 'total_proofs' AND sqlc.narg('sort_direction') = 0 THEN
universe_stats.total_asset_proofs END,
CASE WHEN sqlc.narg('sort_by') = 'total_proofs' AND sqlc.narg('sort_direction') = 1 THEN
universe_stats.total_asset_proofs END DESC,
CASE WHEN sqlc.narg('sort_by') = 'genesis_height' AND sqlc.narg('sort_direction') = 0 THEN
asset_info.genesis_height END,
CASE WHEN sqlc.narg('sort_by') = 'genesis_height' AND sqlc.narg('sort_direction') = 1 THEN
asset_info.genesis_height END DESC,
CASE WHEN sqlc.narg('sort_by') = 'total_supply' AND sqlc.narg('sort_direction') = 0 THEN
asset_supply END,
CASE WHEN sqlc.narg('sort_by') = 'total_supply' AND sqlc.narg('sort_direction') = 1 THEN
asset_supply END DESC
LIMIT @num_limit OFFSET @num_offset;
tapdb/universe_stats_test.go
Outdated
@@ -247,81 +247,247 @@ func TestUniverseQuerySyncStatsSorting(t *testing.T) { | |||
|
|||
// sortCheck is used to generate an IsSorted func bound to the | |||
// response, for each sort type below. | |||
type sortCheck func([]universe.AssetSyncSnapshot) func(i, j int) bool | |||
type sortCheck func([]universe.AssetSyncSnapshot, universe.SortDirection) func(i, j int) bool |
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.
nit: line length, break before universe.SortDirection
.
tapdb/universe_stats_test.go
Outdated
|
||
return func(i, j int) bool { | ||
return s[i].AssetName < s[j].AssetName | ||
if d == universe.SortAscending { |
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.
We could extract all of these individual isSortedFunc
into a single one, now that they have become a bit more complicated.
For example:
isSorted := func(s []universe.AssetSyncSnapshot,
t universe.SyncStatsSort,
d universe.SortDirection) func(i, j int) bool {
asc := d == universe.SortAscending
desc := d == universe.SortDescending
return func(i, j int) bool {
switch {
case t == universe.SortByAssetName && asc:
return s[i].AssetName < s[j].AssetName
case t == universe.SortByAssetName && desc:
return s[i].AssetName > s[j].AssetName
...
}
}
}
Thanks very much for the PR! @jamaljsr will test shortly |
tACK. I tested the functionality. LGTM 👌 |
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.
A few more nits, then this is good to go.
And can you please squash your commits into a single one? Thanks!
Hey @ben2077 we'd love to get this PR in by the 14th, do you think that's possible? |
no problem. |
4876be9
to
9760697
Compare
…et Stats - Introduced ascending and descending sorting options for the Universe Asset Stats query. - Added 'total_supply' field to Universe Asset Stats, enhancing the available dataset. - Enhanced TestUniverseQuerySyncStatsSortingDirection to validate new sorting mechanisms and the inclusion of total_supply. - Optimized SQL for efficient sorting based on user-selected parameters.
017003e
to
280012c
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.
LGTM 🪁
Thanks for such a great first contribution PR!
Implement sorting functionality and add total_supply for Universe Asset Stats