Skip to content

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

Description

@zealot128

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions