Skip to content
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

Fix incentives query filtering #1759

Merged
merged 10 commits into from
Jun 15, 2022
Merged

Fix incentives query filtering #1759

merged 10 commits into from
Jun 15, 2022

Conversation

hieuvubk
Copy link
Contributor

Closes: #1218

What is the purpose of the change

Fix gauges query filter:

handle accumulate
no use GetActiveGauges anymore in ActiveGaugesPerDenom query
no use GetUpcomingGauges anymore in UpcommingGaugesPerDenom query
Add more test

@hieuvubk hieuvubk requested a review from a team June 10, 2022 18:35
return false, nil
}
if accumulate {
gauges = append(gauges, newGauges...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be appending a single element, i.e. newGauges[i] instead of the entire slice each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure, my mistake

Comment on lines 132 to 133
}
for i := 0; i < len(newGauges); i++ {
Copy link
Contributor

@alexanderbez alexanderbez Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
for i := 0; i < len(newGauges); i++ {
}
for i, g := range newGauges {

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Since your touching this area, would you be open to de-duplicating logic across:

Gauges, ActiveGauges, UpcomingGauges, ActiveGaugesByDenom, etc?

Basically make a generic method that takes in the prefix, and an optional parameter for 'denom', and re-uses all of the logic here? It would be a very welcome 100 line deletion here :)

Also can you add a comment above the

newGauges, err := q.getGaugeFromIDJsonBytes(ctx, value)

line saying to the extent of "This may return multiple gauges at once if two gauges start at the same time. For now this is treated as an edge case that is not of importance"

@hieuvubk
Copy link
Contributor Author

Thanks for the PR!

Since your touching this area, would you be open to de-duplicating logic across:

Gauges, ActiveGauges, UpcomingGauges, ActiveGaugesByDenom, etc?

Basically make a generic method that takes in the prefix, and an optional parameter for 'denom', and re-uses all of the logic here? It would be a very welcome 100 line deletion here :)

Also can you add a comment above the

newGauges, err := q.getGaugeFromIDJsonBytes(ctx, value)

line saying to the extent of "This may return multiple gauges at once if two gauges start at the same time. For now this is treated as an edge case that is not of importance"

thanks for the suggestion.
I moved duplicate logic to �a separate function, filtering by prefix types and denom.

@hieuvubk hieuvubk requested a review from ValarDragon June 14, 2022 16:17
// For now this is treated as an edge case that is not of importance
newGauges, err := q.getGaugeFromIDJsonBytes(ctx, value)
if err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
panic(err)
return false, err

// For now this is treated as an edge case that is not of importance
newGauges, err := q.getGaugeFromIDJsonBytes(ctx, value)
if err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
panic(err)
return false, err

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM! Can you add a bug fix changelog entry, for making gauge queries respect pagination?

Then I think this is good to go!

@hieuvubk
Copy link
Contributor Author

Thanks, this LGTM! Can you add a bug fix changelog entry, for making gauge queries respect pagination?

Then I think this is good to go!

Yes I did

@hieuvubk hieuvubk requested a review from ValarDragon June 15, 2022 06:55
@ValarDragon ValarDragon merged commit b464728 into osmosis-labs:main Jun 15, 2022
@ValarDragon ValarDragon added the A:backport/v10.x backport patches to v10.x branch label Jun 15, 2022
mergify bot pushed a commit that referenced this pull request Jun 15, 2022
* fix filtering logic

* add test

* format

* fix: append element in loop

* use range

* optimize code, make filtering into a separate function

* format

* add to changelog

(cherry picked from commit b464728)

# Conflicts:
#	x/incentives/keeper/grpc_query_test.go
ValarDragon pushed a commit that referenced this pull request Jun 15, 2022
* Fix incentives query filtering (#1759)

Co-authored-by: Hieu Vu <[email protected]>
@github-actions github-actions bot mentioned this pull request May 1, 2024
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v10.x backport patches to v10.x branch C:x/incentives
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix filtered paginate in the incentives module
3 participants