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

Add a FindOption to control SeekDirection of Storage.Find #2789

Closed
roman-khimov opened this issue Jul 9, 2022 · 1 comment · Fixed by #2819
Closed

Add a FindOption to control SeekDirection of Storage.Find #2789

roman-khimov opened this issue Jul 9, 2022 · 1 comment · Fixed by #2819
Labels
discussion Initial issue state - proposed but not yet accepted

Comments

@roman-khimov
Copy link
Contributor

Summary or problem description
Storage.Find contract API exposed by the system allows to iterate over a set of keys with various options, but it only does so in one direction (ascending) even though the DataCache/Snapshot behind the scenes has a definition of SeekDirection and therefore is able to seek through the elements in descending order. Depending on the contract's storage schema and the nature of the data stored there might be a need to get X number of the latest values from a set, currently this requires iterating over the whole set till it ends.

Do you have any solution you want to propose?
Add a new flag to FindOptions to control the SeekDirection and allow to iterate over a set of KV pairs in descending (backwards) order.

Neo Version

  • Neo 3

Where in the software does this update applies to?

  • SDK
@roman-khimov roman-khimov added the discussion Initial issue state - proposed but not yet accepted label Jul 9, 2022
@roman-khimov
Copy link
Contributor Author

BTW, native contracts (Neo and RoleManagement) use SeekDirection.Backward already, they're not constrained by the Storage.Find API.

roman-khimov added a commit to roman-khimov/neo that referenced this issue Sep 27, 2022
Depending on the data scheme contracts may want to iterate over prefix in
descending order. Fixes neo-project#2789.
roman-khimov added a commit to roman-khimov/neo that referenced this issue Sep 27, 2022
Depending on the data scheme contracts may want to iterate over prefix in
descending order. Fixes neo-project#2789.
shargon added a commit that referenced this issue Apr 12, 2023
…2819)

* SmartContract: add FindOptions.Backwards to iterate in reverse order

Depending on the data scheme contracts may want to iterate over prefix in
descending order. Fixes #2789.

* Ternary!

Syntax sweetener.

Co-authored-by: Anna Shaleva <shaleva.ann@gmail.com>

* Update src/Neo/SmartContract/FindOptions.cs

Co-authored-by: Erik Zhang <erik@neo.org>

* Persistence: move deferred part of the Find to a method of its own

And add a test for null/empty cases.

---------

Co-authored-by: Anna Shaleva <shaleva.ann@gmail.com>
Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Erik Zhang <erik@neo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant