-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
rpc: add sort_order in tx_search #4253
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.
- this needs an actual test case
- rpc: add sort_order in tx_search #4253 (comment)
… into tx-search deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
@melekes I have added test cases and removed unnecessary sorting from kv-store. Please have a look. |
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 changes. I have a few more comments though...
} | ||
} | ||
|
||
if orderBy == "desc" { |
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.
switch orderBy {
case "desc":
...
case "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.
@melekes actually this will create issue because by default we wanted to keep "asc" order but, if we will use switch case then if someone will not specify the correct order then the transaction will be unordered.
@@ -101,5 +103,29 @@ func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int | |||
} | |||
} | |||
|
|||
if len(apiResults) > 1 { | |||
for _, item := range apiResults { |
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 explain what this loop does? it looks like it just appends apiResults to itself.
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, you are correct @melekes. But, it will remove the nil items present in the array. So, we will only get the txs which are not null. If we will allow nil items then, at the time of order by it will not able to sort correctly and it will fail because, the one item from (a,b) is nil.
@@ -221,60 +221,6 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) { | |||
assert.Equal(t, []*types.TxResult{txResult}, results) | |||
} | |||
|
|||
func TestTxSearchMultipleTxs(t *testing.T) { |
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 remove??
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.
Because we have removed #4253 (comment)
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.
RIght. But we still want to test "indexed fourth (to test we don't include txs with similar events)" use-case. See #2908
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.
So should I take back #4253 (comment)?
// Transaction should be in the ascending order | ||
result, err = c.TxSearch(fmt.Sprintf("tx.height >= 1"), true, 1, 30, "asc") | ||
require.Nil(t, err, "%+v", err) | ||
for k := 0; k < len(result.Txs)-1; k++ { |
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.
here we only have one transaction, so this does not actually test what we want
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.
Actually there are multiple. Throughout the test, many tx has been performed.
@@ -221,60 +221,6 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) { | |||
assert.Equal(t, []*types.TxResult{txResult}, results) | |||
} | |||
|
|||
func TestTxSearchMultipleTxs(t *testing.T) { |
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.
RIght. But we still want to test "indexed fourth (to test we don't include txs with similar events)" use-case. See #2908
Closing in favor of #4342. |
I have added
order_by
which can be"asc" or "desc"
(should be in string format) in thetx_search
RPC method.Fixes: #3333