Skip to content

Commit 341c20f

Browse files
committed
fix(tests): clear query cache on insert
Since [rails pull request #52428][1], `#execute_batch` does not trigger a cache clear anymore. However, `#insert_fixtures_set` relies on that clear to ensure consistency. In the postgresql adapter, this is ensured by a call to `#execute` rather than `#execute_batch` in `#disable_referential_integrity`. Since we are not always calling `#disable_referential_integrity`, we need to ensure that the cache is cleared when running our statements by calling `#execute` instead of `#execute_batch`. [1]: rails/rails#52428 Signed-off-by: Ulysse Buonomo <[email protected]>
1 parent 57ac7e1 commit 341c20f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/active_record/connection_adapters/cockroachdb/database_statements.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ module DatabaseStatements
2222
def insert_fixtures_set(fixture_set, tables_to_delete = [])
2323
fixture_inserts = build_fixture_statements(fixture_set)
2424
table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" }
25-
statements = table_deletes + fixture_inserts
25+
statements = (table_deletes + fixture_inserts).join(";")
26+
27+
# Since [rails pull request #52428][1], `#execute_batch` does not
28+
# trigger a cache clear anymore. However, `#insert_fixtures_set`
29+
# relies on that clear to ensure consistency. In the postgresql
30+
# adapter, this is ensured by a call to `#execute` rather than
31+
# `#execute_batch` in `#disable_referential_integrity`. Since
32+
# we are not always calling `#disable_referential_integrity`,
33+
# we need to ensure that the cache is cleared when running
34+
# our statements by calling `#execute` instead of `#execute_batch`.
35+
#
36+
# [1]: https://github.com/rails/rails/pull/52428
2637

2738
begin # much faster without disabling referential integrity, worth trying.
2839
transaction(requires_new: true) do
29-
execute_batch(statements, "Fixtures Load")
40+
execute(statements, "Fixtures Load")
3041
end
3142
rescue
3243
disable_referential_integrity do
33-
execute_batch(statements, "Fixtures Load")
44+
execute(statements, "Fixtures Load")
3445
end
3546
end
3647
end

0 commit comments

Comments
 (0)