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

Bug/Slow: Truncation very slow in case of many tables (PG) #34

Open
zealot128 opened this issue Apr 25, 2024 · 0 comments
Open

Bug/Slow: Truncation very slow in case of many tables (PG) #34

zealot128 opened this issue Apr 25, 2024 · 0 comments

Comments

@zealot128
Copy link

zealot128 commented Apr 25, 2024

We have about 150 tables and are using PostgreSQL. After switching to a cloud development VM with probable slower Hard Drive access, we noticed a delay for starting the test suite each time.

We saw the TRUNCATE table statements in Test log:
grafik

And found, that factory_bot-preload will truncate all table every time. In sum, that took us 3 extra seconds boot time.

Environment

  • Ruby 3.3.0
  • Rails 7.1.3.2
  • PG 16.2
  • Ubuntu 22 Cloud VM - 8 core, 32 GB RAM - PgTune config applied.

Workaround

We only use 3 preload factories that touches only 4 tables, so we overrode the tables that FactoryBot::Preload truncates:

# spec_helper / test_helper
module FactoryBot
  module Preload
    def self.active_record_names
      %w[organisations domains users memberships]
    end
  end
end

Ideas for a full fix

  • Maybe make the tables configurable
  • Faster SSD / No CoudVM but local or Bare Metal needed
  • Maybe better to batch all truncations into one call?
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