Skip to content

Conversation

@BuonOmo
Copy link
Collaborator

@BuonOmo BuonOmo commented Jan 5, 2025

Improve performance of the #disable_referential_integrity by fetching every foreign keys at once. This method is where most time is spent in tests, hence this PR helps dividing by 3 our test suite time.

@BuonOmo BuonOmo force-pushed the faster-ref-integrity branch 4 times, most recently from 0e5baae to 945c57c Compare January 6, 2025 10:04
@BuonOmo BuonOmo marked this pull request as ready for review January 6, 2025 10:05
@BuonOmo BuonOmo force-pushed the faster-ref-integrity branch from 945c57c to 6afe199 Compare January 6, 2025 10:45

# This overrides the method from PostegreSQL adapter
# Resets the sequence of a table's primary key to the maximum value.
def reset_pk_sequence!(table, pk = nil, sequence = nil)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the difference lied in a condition database_version < 10, which will never be true in our codebase!

options[:deferrable] = extract_constraint_deferrable(row["deferrable"], row["deferred"])

options[:validate] = row["valid"]
to_table = PostgreSQL::Utils.unquote_identifier(row["to_table"])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already done a few lines ago

# Normally, the primary keys would use CockroachDB's unique_rowid().
def test_create_symbol_fixtures
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :collections, collections: Course) { Course.lease_connection }
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :collections, collections: Course)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mimicking upstream change

Copy link
Contributor

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really great speedup, thank you! Also, the new debugging functions look very useful.

@rafiss rafiss merged commit 8daf4fb into master Jan 6, 2025
4 checks passed
@BuonOmo BuonOmo deleted the faster-ref-integrity branch January 6, 2025 16:47
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

Successfully merging this pull request may close these issues.

2 participants