graphprotocol / graphprotocol/graph-node

Feature: `.findMany` & `.saveMany`

オープン
#3,618 コメント 4 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Stale
主要言語
Rust
スター
3.2k
フォーク
1.1k
平均マージ
4日 1時間
マージ済み PR(30日)
1

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提案で説明されている注入されたエンティティ API から始め、その意図された findMany および saveMany の動作を Prisma V2 の findMany リファレンスと比較します。一括読み取り、順序付け、書き込みのセマンティクスを定義し、関連する実装およびテストのエントリポイントを特定します。完了の条件は、サブグラフが繰り返し行っているエンティティの読み込みと保存を、これらの操作で置き換えられることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust, typescript
領域
api, backend-api-design, databases
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。