Feature: `.findMany` & `.saveMany`

Đang mở
#3,618 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust, typescript

Hướng nghiên cứu

Bắt đầu với entity API được inject được mô tả trong proposal và so sánh các hành vi dự kiến của findMany và saveMany với tài liệu tham chiếu findMany của Prisma V2. Xác định ngữ nghĩa của việc đọc hàng loạt, sắp xếp và ghi, sau đó xác định các điểm vào triển khai và kiểm thử liên quan; hoàn thành khi các subgraph có thể thay thế việc tải và lưu entity lặp lại bằng các thao tác này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Stale

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

Ngôn ngữ chính
Rust
Star
3.2k
Fork
1.1k
Merge trung bình
4 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của graphprotocol/graph-node

Tất cả issue của graphprotocol/graph-node

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.