added comments for future solution
This commit is contained in:
parent
e44b84c18c
commit
0cbc7d99c2
1 changed files with 20 additions and 10 deletions
|
@ -22,7 +22,17 @@ func (c *Client) ContainersOf(idUser *user.ID) ([]cid.ID, error) {
|
|||
rawID = idUser.WalletBytes()
|
||||
}
|
||||
|
||||
// We would like to have batch size as big as possible,
|
||||
// to reduce the number of round-trips and avoid creating sessions.
|
||||
// The limit depends on 2 things:
|
||||
// 1. VM limits: max 2048 items on stack.
|
||||
// 2. JSON encoded size for the item with type = 128k.
|
||||
// It turns out, that for container ID the second limit is hit first,
|
||||
// 512 is big enough value and it is beautiful.
|
||||
const batchSize = 512
|
||||
|
||||
var cidList []cid.ID
|
||||
wasSent := false
|
||||
cb := func(item stackitem.Item) error {
|
||||
rawID, err := client.BytesFromStackItem(item)
|
||||
if err != nil {
|
||||
|
@ -37,26 +47,26 @@ func (c *Client) ContainersOf(idUser *user.ID) ([]cid.ID, error) {
|
|||
}
|
||||
|
||||
cidList = append(cidList, id)
|
||||
if len(cidList) == batchSize { // that's wrong check, need to fix
|
||||
wasSent = true
|
||||
// do send() and return
|
||||
}
|
||||
wasSent = false
|
||||
return nil
|
||||
}
|
||||
|
||||
// We would like to have batch size as big as possible,
|
||||
// to reduce the number of round-trips and avoid creating sessions.
|
||||
// The limit depends on 2 things:
|
||||
// 1. VM limits: max 2048 items on stack.
|
||||
// 2. JSON encoded size for the item with type = 128k.
|
||||
// It turns out, that for container ID the second limit is hit first,
|
||||
// 512 is big enough value and it is beautiful.
|
||||
const batchSize = 512
|
||||
|
||||
cnrHash := c.client.ContractAddress()
|
||||
err := c.client.Morph().TestInvokeIterator(cb, batchSize, cnrHash, containersOfMethod, rawID)
|
||||
if err != nil {
|
||||
if errors.Is(err, unwrap.ErrNoSessionID) {
|
||||
return c.list(idUser)
|
||||
return c.list(idUser) // <- here it returns the WHOLE list, need to break in batches n send()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !wasSent {
|
||||
// do send() the rest
|
||||
}
|
||||
|
||||
return cidList, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue