added comments for future solution

This commit is contained in:
Ekaterina Lebedeva 2024-12-20 12:27:53 +03:00
parent e44b84c18c
commit 0cbc7d99c2

View file

@ -22,7 +22,17 @@ func (c *Client) ContainersOf(idUser *user.ID) ([]cid.ID, error) {
rawID = idUser.WalletBytes() 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 var cidList []cid.ID
wasSent := false
cb := func(item stackitem.Item) error { cb := func(item stackitem.Item) error {
rawID, err := client.BytesFromStackItem(item) rawID, err := client.BytesFromStackItem(item)
if err != nil { if err != nil {
@ -37,26 +47,26 @@ func (c *Client) ContainersOf(idUser *user.ID) ([]cid.ID, error) {
} }
cidList = append(cidList, id) 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 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() cnrHash := c.client.ContractAddress()
err := c.client.Morph().TestInvokeIterator(cb, batchSize, cnrHash, containersOfMethod, rawID) err := c.client.Morph().TestInvokeIterator(cb, batchSize, cnrHash, containersOfMethod, rawID)
if err != nil { if err != nil {
if errors.Is(err, unwrap.ErrNoSessionID) { 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 return nil, err
} }
if !wasSent {
// do send() the rest
}
return cidList, nil return cidList, nil
} }