graphprotocol / graphprotocol/graph-node
Feature: `.findMany` & `.saveMany`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Rust
- Stelle
- 3.2k
- Fork
- 1.1k
- Merge medio
- 4g 1h
- PR unite (30g)
- 1
Descrizione
Proposal
The injected entity API should also expose bulk operations like findMany, saveMany. This seems like a simple addition to me that would enable better bulk operations and indexing-time aggregations like storing a rank, percentiles, etc.
By the example of the Eden Network Subgraph, that would enable them to save a lot of database reads and writes:
Instead of (simplified ranking logic from them):
let stakers = network.stakers.map<Staker | null>(id => Staker.load(id)).filter(staker => staker != null);
let sortedStakers = stakers((a, b) =>
b.staked.div(WEI).minus(a.staked.div(WEI)).toI32()
);
sortedStakers.forEach((staker, index) => {
staker.rank = BigInt.fromI32(index);
staker.save();
});
They could do something like:
let stakers = Stakers.findMany({ orderBy: { staked: 'desc' } });
let rankedStakers = sortedStakers.map((staker, index) => {
staker.rank = BigInt.fromI32(index);
return staker;
});
Stakers.saveMany(rankedStakers);
Currently, they have ~7000 stakers. That addition would save them 14k-2 database operations.
Current behaviour
In order to update multiple entities in one mapping, subgraph developers are forced to store the ids of all entities that they would like to update in an array on a global singleton entity. That leads to unnecessary big arrays in the database and unnecessary amount of reads and writes.
Affected subgraphs
- Eden Network
- Superfluid
- ...
Inspiration
I personally think the Prisma V2 ORM is pretty well designed: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’API delle entità iniettata descritta nella proposta e confronta i comportamenti previsti di findMany e saveMany con il riferimento findMany di Prisma V2. Definisci la semantica della lettura in blocco, dell’ordinamento e della scrittura, quindi individua i punti di ingresso pertinenti per l’implementazione e i test; il lavoro è completato quando i subgraph possono sostituire i caricamenti e i salvataggi ripetuti delle entità con queste operazioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, typescript
- Ambito
- api, backend-api-design, databases
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100