-
Notifications
You must be signed in to change notification settings - Fork 493
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
ledger: fix lookupLatest usage of the resources cache #3939
ledger: fix lookupLatest usage of the resources cache #3939
Conversation
* In some situations the method might incorrectly count deleted items towards total items * This might result not returning all the resources to REST API clients
Codecov Report
@@ Coverage Diff @@
## master #3939 +/- ##
==========================================
+ Coverage 49.79% 49.80% +0.01%
==========================================
Files 409 409
Lines 68892 68897 +5
==========================================
+ Hits 34303 34313 +10
+ Misses 30884 30881 -3
+ Partials 3705 3703 -2
Continue to review full report at Codecov.
|
@@ -42,29 +42,34 @@ type AppResource struct { | |||
|
|||
// AssignAccountResourceToAccountData assignes the Asset/App params/holdings contained | |||
// in the AccountResource to the given basics.AccountData, creating maps if necessary. | |||
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) { | |||
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned 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.
maybe a comment like
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned bool) { | |
// Returns true if the AccountResource contained a new or updated resource, and false if the AccountResource contained no changes (indicating the resource was deleted). | |
func AssignAccountResourceToAccountData(cindex basics.CreatableIndex, resource AccountResource, ad *basics.AccountData) (assigned 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.
I guess another way to do it (rather than mix it into the Assign method) would be to have a method like
// IsEmpty is maybe not a great name, perhaps there is something clearer
func (r *AccountResource) IsEmpty() bool {
return r.AssetParams == nil && r.AssetHolding == nil && r.AppLocalState == nil && r.AppParams == nil
}
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 thought about checking in addResource
but I think AssignAccountResourceToAccountData
is a right place because 1) it has "insertion" logic 2) it basically creates the output data structure 3) it is used only in addResource
.
Updated the AssignAccountResourceToAccountData
comment as suggested.
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.
Glad you found this, I did not consider needing to skip counting empty AccountResources.. LGTM, just a minor point about comments or alternate IsEmpty() approach that might make it easier to read
Summary
deleted items towards total items
REST API clients
Test Plan
Test added