[Feature Request] Support query batching (prisma fluent api)
Maintainer thường phản hồi trong vòng 1 ngày
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
- 15/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ệ
- typescript
Hướng nghiên cứu
This asks for query batching (a dataloader-style layer) so that per-parent lookups issued in the same tick collapse into one WHERE id IN (...) query, and it notes the Prisma fluent API was not ported during the Kysely rewrite. Start by reading how the current query engine executes findMany/findUnique calls and where a per-tick queue could be hooked in, then look at how Prisma's fluent API batches. Nothing here names a file or a test, so expect design discussion before code; done means concurrent per-parent queries produce a single batched SQL statement.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
When using any orm for a graphql server, there is a common n+1 problem. E.g. consider this query which fetches all users with their posts:
query {
users {
username
posts {
name
}
}
}
The way a common graphql server resolves this is by first fetching all users and then for each executing a query to fetch his posts, the calls to the zenstack orm are equivalent to:
db.user.findMany();
db.post.findMany({ where: { user_id: 1 } });
db.post.findMany({ where: { user_id: 2 } });
db.post.findMany({ where: { user_id: 3 } });
Which corresponds to roughly these sql queries (n+1 queries):
SELECT * FROM users; -- user ids: 1, 2, 3
SELECT * FROM posts WHERE user_id = 1;
SELECT * FROM posts WHERE user_id = 2;
SELECT * FROM posts WHERE user_id = 3;
In prisma there is an integrated dataloader which automatically batches similar queries in the same js tick, so it results in the following (2 queries) when using the fluent API:
db.user.findMany();
db.user.findUnique({ where: { id: 1 } }).posts();
db.user.findUnique({ where: { id: 2 } }).posts();
db.user.findUnique({ where: { id: 3 } }).posts();
SELECT * FROM users; -- user ids: 1, 2, 3
SELECT * FROM posts WHERE user_id IN (1, 2, 3);
For that there is the fluent API, which is (per discussion on discord) not ported with the kysely rewrite.
Describe the solution you'd like
The way prisma does it may not be that intuitive and I do not see a reason why only findUnique calls get used for batching. So it would be a great addition if zenstack could support batching and also of more than findUnique calls when they have parameters in common.
Describe alternatives you've considered
Using a custom dataloader implementation ontop of zenstack orm
Additional context
/
- Ngôn ngữ chính
- TypeScript
- Star
- 2.9k
- Fork
- 157
- Merge trung bình
- 11 giờ 42 phút
- Pull request đã merge (30 ngày)
- 20
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của zenstackhq/zenstack
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
zenstackhq/zenstack#2873 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
runtime
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zenstackhq/zenstack#2868 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
zenstackhq/zenstack#2694 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
zenstackhq/zenstack#2659 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
zenstackhq/zenstack#2542 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của zenstackhq/zenstack
Issue tương tự
-
Tenant
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
MTES-MCT/Dossier-Facile-Frontend#2061 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
interledger/publisher-tools#905 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: Cbeebies PL SDĐang mởapproved check:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
iptv-org/iptv#54525 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
DB-plane provider_chat_options.* is accepted by config set but never merged into the loaded configĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:web
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
praetorianer777/GoTome#178 ·
Maintainer thường phản hồi trong vòng 1 ngày