mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Avoid VACUUM on test dbs in Postgres
The Postgres implementation was always faulty, but the database exception was swallowed until See https://github.com/silverstripe/silverstripe-framework/pull/9456. Now that the the exception is only swallowed the first time, the second recurrence will cause failing test execution. This is a bit of an awkward fix, but the indirection "through" DataObject doesn't allow for anything else without changing public API surface. The logic goes from TempDatabase to DBSchemaManager, then through the closure into DataObject->requireTable(), then back into DBSchemaManager->requireTable(). And updateschema() is subclassed in SQLite3, making it difficult to add more arguments. VACUUM is described as: > VACUUM reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a VACUUM is done. Therefore it's necessary to do VACUUM periodically, especially on frequently-updated tables. https://www.postgresql.org/docs/9.1/sql-vacuum.html Since test databases are short-lived, there's no reason to delete dead tuples, they'll be garbage collected when either the transaction is rolled back, or the database is destroyed after the test run.
This commit is contained in:
parent
052c5cbc38
commit
a50e15e5ee
@ -239,29 +239,36 @@ class TempDatabase
|
|||||||
$dataClasses = ClassInfo::subclassesFor(DataObject::class);
|
$dataClasses = ClassInfo::subclassesFor(DataObject::class);
|
||||||
array_shift($dataClasses);
|
array_shift($dataClasses);
|
||||||
|
|
||||||
|
$oldCheckAndRepairOnBuild = Config::inst()->get(DBSchemaManager::class, 'check_and_repair_on_build');
|
||||||
|
Config::modify()->set(DBSchemaManager::class, 'check_and_repair_on_build', false);
|
||||||
|
|
||||||
$schema = $this->getConn()->getSchemaManager();
|
$schema = $this->getConn()->getSchemaManager();
|
||||||
$schema->quiet();
|
$schema->quiet();
|
||||||
$schema->schemaUpdate(function () use ($dataClasses, $extraDataObjects) {
|
$schema->schemaUpdate(
|
||||||
foreach ($dataClasses as $dataClass) {
|
function () use ($dataClasses, $extraDataObjects) {
|
||||||
// Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
|
foreach ($dataClasses as $dataClass) {
|
||||||
if (class_exists($dataClass)) {
|
// Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
|
||||||
$SNG = singleton($dataClass);
|
if (class_exists($dataClass)) {
|
||||||
if (!($SNG instanceof TestOnly)) {
|
$SNG = singleton($dataClass);
|
||||||
$SNG->requireTable();
|
if (!($SNG instanceof TestOnly)) {
|
||||||
|
$SNG->requireTable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If we have additional dataobjects which need schema, do so here:
|
// If we have additional dataobjects which need schema, do so here:
|
||||||
if ($extraDataObjects) {
|
if ($extraDataObjects) {
|
||||||
foreach ($extraDataObjects as $dataClass) {
|
foreach ($extraDataObjects as $dataClass) {
|
||||||
$SNG = singleton($dataClass);
|
$SNG = singleton($dataClass);
|
||||||
if (singleton($dataClass) instanceof DataObject) {
|
if (singleton($dataClass) instanceof DataObject) {
|
||||||
$SNG->requireTable();
|
$SNG->requireTable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
|
Config::modify()->set(DBSchemaManager::class, 'check_and_repair_on_build', $oldCheckAndRepairOnBuild);
|
||||||
|
|
||||||
ClassInfo::reset_db_cache();
|
ClassInfo::reset_db_cache();
|
||||||
DataObject::singleton()->flushCache();
|
DataObject::singleton()->flushCache();
|
||||||
|
Loading…
Reference in New Issue
Block a user