- Minimize the number of database hits by grouping multiple single-row transactions into multi-row batch transactions.
- Transform the data in memory using vectorized operators.
- Use the MakerDAO
Multicallcontract to batch EVM state queries. - Use
XXX.getMany()to batch Substrate state queries.
Create and Update, that are emitted once the record is created or updated. The data batch received by the processor is then an array of event items, i.e.
Patterns
An idiomatic use ofprocessor.run() is as follows:
Anti-patterns
Avoid loading or persisting single entities unless strictly necessary. For example, here is a possible antipattern for the Gravatar example:Migrate from handlers
Batch-based processing can be used as a drop-in replacement for the handler-based mappings employed by e.g. subgraphs. While the handler-based processing is significantly slower due to excessive database lookups and writes, it may be a good intermediary step while migrating an existing subgraph to Squid SDK. One can simply re-use the existing handlers while looping over thectx items: