Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly excessive transaction count with ActiveRecord #22

Open
tobypinder opened this issue Mar 25, 2015 · 0 comments
Open

Possibly excessive transaction count with ActiveRecord #22

tobypinder opened this issue Mar 25, 2015 · 0 comments

Comments

@tobypinder
Copy link

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 1af146f 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!

@botandrose botandrose transferred this issue from DatabaseCleaner/database_cleaner Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant