Reducing N+1 queries by eager loading
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
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- rails, ruby
- Lĩnh vực
- api, backend, performance
Hướng nghiên cứu
Bắt đầu bằng cách lần theo resources controller, phương thức records và phần xử lý include được mô tả cho ProjectResource và CompanyResource. Tái hiện trường hợp /api/projects?include=company và so sánh với company.subscription; hoàn tất có nghĩa là dữ liệu phụ thuộc được các thuộc tính được tính toán sử dụng được eager load mà không yêu cầu client phải yêu cầu relationship đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I read through the documentation and couldn't find a built-in solution to this problem. When certain models are serialized we need to make sure that the query to retrieve that entity always adds an includes to avoid all the lazy loaded N+1 queries. We can do this via records as long as the request is on the resources controller. If it's not then I couldn't see a place to extend it.
Let me give an example
class ProjectResource
has_one :company
end
class CompanyResource
attribute :plan_start_at
def plan_start_at
@model.subscription.created_at
end
end
As you'll notice each time a company is rendered it is going to retrieve a value out of it's subscription. However, the problem comes in when we request a URL like this
/api/projects?include=company
It's using the records method off of the projects resource and even when it goes to process the include on company it's not calling records on the company resource so we end up with a separate query for every companies subscription.
Now, from what I can tell maybe this is supposed to be taken care of by also requesting the subscription like this
/api/projects?include=company,company.subscription
However this doesn't completely work since I don't need the subscription object and requesting the subscription isn't a concern of the client (since we simply need the subscription in order to calculate a property on the company.)
- Ngôn ngữ chính
- Ruby
- Star
- 2.3k
- Fork
- 546
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
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 JSONAPI-Resources/jsonapi-resources
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
ArgumentError with Rails 8.1 Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 bình luận · 1 reaction ·
-
Fields filtering with include Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của JSONAPI-Resources/jsonapi-resources
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
バグ
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Version bump for OpenVox 9 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
voxpupuli/puppet-epel#186 · 1 bình luận ·