Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Possibly excessive transaction count with ActiveRecord

Aperta
#22 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
databases, testing

Direzione di ricerca

Inizia da lib/database_cleaner/active_record/transaction.rb intorno alla riga 12, poi leggi git blame/log per i commit 1af146fb80fef05acca0d1a322bb6987af645cc0 e database_cleaner#200. Riproduci il conteggio di BEGIN/COMMIT per test con la configurazione RSpec mostrata e verifica che qualsiasi modifica preservi il comportamento corretto da #200 eliminando al contempo il lavoro non necessario sulle transazioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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!

Lingua principale
Ruby
Stelle
76
Fork
76
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DatabaseCleaner/database_cleaner-active_record

Tutte le issue di DatabaseCleaner/database_cleaner-active_record

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.