Skip to content

Commit 34d20bc

Browse files
authored
Merge pull request #87 from cosmocode/optimize
Try optimizing the database before closing the connection
2 parents 1b58dea + 549d6b8 commit 34d20bc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

SQLiteDB.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ public function __construct($dbname, $schemadir, $sqlitehelper = null)
8181
Functions::register($this->pdo);
8282
}
8383

84+
/**
85+
* Try optimizing the database before closing the connection.
86+
*
87+
* @see https://www.sqlite.org/pragma.html#pragma_optimize
88+
*/
89+
public function __destruct()
90+
{
91+
try {
92+
$this->exec("PRAGMA analysis_limit=400");
93+
$this->exec('PRAGMA optimize;');
94+
} catch (\Exception $e) {
95+
// ignore failures, this is not essential and not available until 3.18.0.
96+
}
97+
}
98+
8499
/**
85100
* Do not serialize the DB connection
86101
*

0 commit comments

Comments
 (0)