@@ -115,18 +115,18 @@ fn generate_first_placeholder_handler(
115115 format ! (
116116 r#"
117117export function handle{event_name}(event: {event_name}Event): void {{
118- // Entities can be loaded from the store using a string ID; this ID
119- // needs to be unique across all entities of the same type
120- let entity = ExampleEntity.load(
121- event.transaction.hash.concat(Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex)))
118+ // Entities can be loaded from the store using their id; using 'Bytes' as
119+ // the id type is more efficient than 'ID' or 'String' and should be used
120+ // whenever possible.
121+ const id = event.transaction.hash.concat(
122+ Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex))
122123 )
124+ let entity = ExampleEntity.load(id)
123125
124126 // Entities only exist after they have been saved to the store;
125127 // `null` checks allow to create entities on demand
126128 if (!entity) {{
127- entity = new ExampleEntity(
128- event.transaction.hash.concat(Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex)))
129- )
129+ entity = new ExampleEntity(id)
130130
131131 // Entity fields can be set using simple assignments
132132 entity.count = BigInt.fromI32(0)
@@ -139,12 +139,6 @@ export function handle{event_name}(event: {event_name}Event): void {{
139139{field_assignments}
140140 entity.save()
141141
142- // Note: If a handler doesn't require existing field values, it is faster
143- // _not_ to load the entity from the store. Instead, create it only once with
144- // `new Entity(...)`, set the fields that should be updated and save the
145- // entity back to the store. Fields that were not set or unset remain
146- // unchanged, allowing for partial updates to be applied.
147-
148142 // It is also possible to access smart contracts from mappings. For
149143 // example, the contract that has emitted the event can be connected to
150144 // with:
0 commit comments