Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Chaincode Pagination with query[Asset]s. #131

Merged
merged 8 commits into from
Dec 7, 2020

Conversation

Kelvin-M
Copy link
Contributor

@Kelvin-M Kelvin-M commented Nov 26, 2020

Description

The aim of this PR is to add chaincode pagination for query[Asset]s.
It's based on :

Closes issue(s)

None

Companion PRs

Substra/substra-backend#352

How to test / repro

Launch e2e tests, no regression should appear.

Screenshots / Trace

None

Changes include

  • Use GetStateByPartialCompositeKeyWithPagination instead of GetStateByPartialCompositeKey
  • Return bookmark to the user and and bookmark args
  • Update tests

Checklist

  • I have tested this code
  • I have updated examples
  • Restore old limit value (5 -> 500)

Other comments

@Kelvin-M Kelvin-M changed the base branch from master to add-channel-log November 27, 2020 16:01
@AurelienGasser AurelienGasser force-pushed the chaincode-pagination branch 2 times, most recently from 2af5e83 to d5139b0 Compare November 27, 2020 21:12
@AurelienGasser
Copy link
Contributor

@Kelvin-M I moved to a simpler string bookmark structure.

For the getModels special case, I used a JSON-ified structure.

I also made sure smart contracts that support bookmarks always return a bookmark in the chaincode response:

{
result interface{}
bookmark string
}

even when the bookmark is "". This way the return type is consistent accross calls.

Lastly I added 2 unit tests:

  • one for traintuples (basic case)
  • one for getModels (specia case)

I had to make changes to the mock stub to support pagination.

Please let me know if all that looks good to you.

Base automatically changed from add-channel-log to master November 30, 2020 10:23
@Kelvin-M Kelvin-M marked this pull request as ready for review November 30, 2020 16:58
Copy link
Contributor

@thibaultrobert thibaultrobert left a comment

Choose a reason for hiding this comment

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

A few feedback but feel free to ignore them.

Nice to see the start of pagination.

chaincode/algo.go Show resolved Hide resolved
Comment on lines +100 to +105
if len(args) > 1 {
err = errors.BadRequest("incorrect number of arguments, expecting at most one argument")
return
}
elementsKeys, err := db.GetIndexKeys("aggregateAlgo~owner~key", []string{"aggregateAlgo"})

if len(args) == 1 && args[0] != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and others following that I will not comment on.

chaincode/main.go Show resolved Hide resolved
chaincode/ledger_db.go Show resolved Hide resolved
@AurelienGasser AurelienGasser merged commit f2ba798 into master Dec 7, 2020
@AurelienGasser AurelienGasser deleted the chaincode-pagination branch December 7, 2020 19:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants