|
8 | 8 | "github.com/massalabs/station/pkg/node" |
9 | 9 | ) |
10 | 10 |
|
| 11 | +const datastoreBatchSize = 64 |
| 12 | + |
11 | 13 | // Fetch retrieves the complete data of a website as bytes. |
12 | 14 | func Fetch(network *config.NetworkInfos, websiteAddress string) ([]byte, error) { |
13 | 15 | client := node.NewClient(network.NodeURL) |
@@ -51,18 +53,28 @@ func fetchAllChunks(client *node.Client, websiteAddress string, chunkNumber int3 |
51 | 53 | keys[i] = convert.I32ToBytes(i) |
52 | 54 | } |
53 | 55 |
|
54 | | - response, err := node.ContractDatastoreEntries(client, websiteAddress, keys) |
55 | | - if err != nil { |
56 | | - return nil, fmt.Errorf("calling get_datastore_entries '%+v': %w", keys, err) |
57 | | - } |
| 56 | + var dataStore []byte |
58 | 57 |
|
59 | | - if len(response) != int(chunkNumber) { |
60 | | - return nil, fmt.Errorf("expected %d entries, got %d", chunkNumber, len(response)) |
61 | | - } |
| 58 | + for start := 0; start < int(chunkNumber); start += datastoreBatchSize { |
| 59 | + end := start + datastoreBatchSize |
| 60 | + if end > int(chunkNumber) { |
| 61 | + end = int(chunkNumber) |
| 62 | + } |
62 | 63 |
|
63 | | - var dataStore []byte |
64 | | - for _, entry := range response { |
65 | | - dataStore = append(dataStore, entry.FinalValue...) |
| 64 | + batchKeys := keys[start:end] |
| 65 | + |
| 66 | + response, err := node.ContractDatastoreEntries(client, websiteAddress, batchKeys) |
| 67 | + if err != nil { |
| 68 | + return nil, fmt.Errorf("calling get_datastore_entries '%+v': %w", batchKeys, err) |
| 69 | + } |
| 70 | + |
| 71 | + if len(response) != len(batchKeys) { |
| 72 | + return nil, fmt.Errorf("expected %d entries, got %d", len(batchKeys), len(response)) |
| 73 | + } |
| 74 | + |
| 75 | + for _, entry := range response { |
| 76 | + dataStore = append(dataStore, entry.FinalValue...) |
| 77 | + } |
66 | 78 | } |
67 | 79 |
|
68 | 80 | return dataStore, nil |
|
0 commit comments