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

Possibly excessive transaction count with ActiveRecord

Đang mở
#22 0 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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
databases, testing

Hướng nghiên cứu

Bắt đầu với lib/database_cleaner/active_record/transaction.rb quanh dòng 12, sau đó đọc git blame/log cho các commit 1af146fb80fef05acca0d1a322bb6987af645cc0 và database_cleaner#200. Tái hiện số lượng BEGIN/COMMIT trên mỗi test bằng cấu hình RSpec được cung cấp và kiểm tra rằng mọi thay đổi đều giữ nguyên hành vi đã được sửa trong #200, đồng thời loại bỏ phần xử lý transaction không cần thiết.

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

Mô tả

I am using a standard :transaction DatabaseCleaner block with rspec:

    config.around(:each) do |example|
      DatabaseCleaner[:active_record, connection: :test].cleaning do
        example.run
      end
    end

When trying to profile the queries in the test suite, I noticed there was a large number of COMMIT statements: one for each test, and equivalent to the ROLLBACK query count. After digging, it seems the strategy runs a blank transaction in the DatabaseCleaner#begin block: https://github.com/DatabaseCleaner/database_cleaner/blob/cda982c9b4a8f3f116ed7e39766eb1447e0197aa/lib/database_cleaner/active_record/transaction.rb#L12

From what I can tell with git's blame/log, this was added in 1af146fb80fef05acca0d1a322bb6987af645cc0 and then modified as a fix for DatabaseCleaner/database_cleaner#200. These seem to indicate that this empty transaction only needs to be run once, perhaps at the start of the suite, or perhaps with a flag indicating it's been run once and doesn't need to run again.

It's clearly not the end of the world, but I am currently on a spec optimisation push and this extra BEGIN/COMMIT per test is having a not-insignificant (but admittedly not major) impact on test time: My metrics indicate it's adding about 15 seconds of time to a suite with 6200ish tests.

Happy to help and create a pull request if there's consensus that I haven't misunderstood the purpose of that statement!

Ngôn ngữ chính
Ruby
Star
76
Fork
76
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

  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 DatabaseCleaner/database_cleaner-active_record

Tất cả issue của DatabaseCleaner/database_cleaner-active_record

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.