-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a loadInBlock
host function for mappings
#3459
Comments
I'd would not even call these types "entities", since they are not meant to be queried by graphql. Other things we could call them: |
At least as things are right now, they can be queried from GraphQL just fine; it's just that mappings won't be able to get to them after a block has been processed. |
Rather than creating a new entity-type annotation, would another approach be to introduce a way in the mappings to look into the entity cache for the block (kind of |
Yes, that would be a good approach, too, and I think preferable to yet another annotation. We could call it something like |
What about the (more recommended I think?) |
We still need a primitive for that, but wrapping that with |
writeonly
entityloadInBlock
host function for mappings
PR: #4540 |
In some cases, subgraphs use entities to communicate some information between handlers in the same block (e.g., the
Transaction
entity in Uniswap-like subgraphs) They use them by following the pattern of 'try to load the entity, if it doesn't exist yet, create it'. That leads to considerable slowdowns sincegraph-node
has to go to the database every time to confirm that the entity does indeed not exist yet, even though the subgraph author knows that that is futile. In one case, this pattern caused 20 lookups per second, and the roundtrips to the database took a considerable amount of time (about 10-15% of the overall processing time) even though the actual query takes very little time (under a millisecond). An experiment showed that avoiding these lookups increased block processing speed from 700ms/block to about 500ms/block.We should therefore add a way for subgraph authors to express that an entity is only ever used by the indexing process for the duration of a block. That only makes sense for immutable entities, and we should therefore add another annotation
writeonly: true
for entity declarations which impliesimmutable: true
. The subgraph schema would then look likeThere might be better ways to express that than saying
writeonly
since it is legal to look these entities up withstore.get
in any handler that runs in the same block as the handler that creates the entity; it's only cross-block lookups that would be disabled by this annotation.The text was updated successfully, but these errors were encountered: