entities of type `XXX` can not be updated since they are immutable. Entity ids are [1] 问题排查

今天发布完subgraph的时候控制台报了这样的错误

Error: Failed to transact block operations: internal constraint violated: entities of type `Gravatar` can not be updated since they are immutable. Entity ids are [1]

意思是当前的实体不能更新,因为它们是不可变的!

引用官方文档的一段话:

By default, entities are mutable, meaning that mappings can load existing entities, modify them and store a new version of that entity. Mutability comes at a price, and for entity types for which it is known that they will never be modified, for example, because they simply contain data extracted verbatim from the chain, it is recommended to mark them as immutable with @entity(immutable: true) . Mappings can make changes to immutable entities as long as those changes happen in the same block in which the entity was created. Immutable entities are much faster to write and to query, and should therefore be used whenever possible.

默认情况下,实体是可变的,这意味着映射可以加载现有实体,修改它们并存储该实体的新版本。可变性是有代价的,对于已知永远不会被修改的实体类型,例如,因为它们只是包含从链中逐字提取的数据,建议使用@entity(immutable: true)将它们标记为不可变。映射可以对不可变实体进行更改,只要这些更改发生在创建实体的同一块中。不可变实体的读写速度要快得多,因此应该尽可能使用不可变实体。

也就是说当我们的业务逻辑需要更新存储在graph节点里面的实体时,需要把实体的immutable属性设置为false。

猜你喜欢

转载自blog.csdn.net/gambool/article/details/128687913