Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Identity cache inside transaction

Đang mở
#533 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/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ệ
rails, ruby
Lĩnh vực
database

Hướng nghiên cứu

Bắt đầu bằng cách theo dõi ApplicationRecord.fetch và quyết định should_use_cache? xung quanh các transaction của ActiveRecord. Tái hiện ví dụ lồng nhau với requires_new và joinable: false, sau đó xác minh rằng việc đọc cache diễn ra ở đó mà không thay đổi hành vi nhất quán của cache trong các transaction khác.

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

Mô tả

Identity cache gem does not fetch from the cache store when fetch method was used inside any transaction, this is to avoid inconsistency in cache data as the changes will be commited at the end of transaction.

But they might be use case where we only load and not do updation. One way to solve this having a transaction which is not joinable to parent transaction. Usually identity_cache has should_use_cache? method which decides to fetch from cache or DB. should_use_cache? checks for any open transaction which is joinable, if so it make the DB call instead of fetching from cache. But if we wrap the fetch call inside transaction which is new and not joinable , then we can make use of advantage of the cache store and can save query at many places.

In the below code, fetch is happening inside the new transaction which is not joinable, should_use_cache? method returns true in this case and fetch from cache store.

Sample code:

ApplicationRecord.transaction do
    ApplicationRecord.transaction(requires_new: true, joinable: false) do
        ApplicationRecord.fetch(1)
     end
end
Ngôn ngữ chính
Ruby
Star
2k
Fork
175
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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 Shopify/identity_cache

Tất cả issue của Shopify/identity_cache

Issue tương tự

Thêm issue về Ruby

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.