|
12 | 12 | * @link https://cakephp.org CakePHP(tm) Project |
13 | 13 | * @license https://www.opensource.org/licenses/mit-license.php MIT License |
14 | 14 | */ |
| 15 | + |
15 | 16 | namespace DebugKit\Model\Table; |
16 | 17 |
|
17 | 18 | use Cake\Core\Configure; |
@@ -86,7 +87,17 @@ public function findRecent(SelectQuery $query): SelectQuery |
86 | 87 | */ |
87 | 88 | protected function shouldGc(): bool |
88 | 89 | { |
89 | | - return rand(1, 100) === 100; |
| 90 | + return rand(1, 10) === 10; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Check if garbage collection vacuum should be run |
| 95 | + * |
| 96 | + * @return bool |
| 97 | + */ |
| 98 | + protected function shouldGcVacuum(): bool |
| 99 | + { |
| 100 | + return rand(1, 10) === 10; |
90 | 101 | } |
91 | 102 |
|
92 | 103 | /** |
@@ -131,7 +142,26 @@ public function gc(): void |
131 | 142 |
|
132 | 143 | $conn = $this->getConnection(); |
133 | 144 | if ($conn->getDriver() instanceof Sqlite) { |
134 | | - $conn->execute('VACUUM;'); |
| 145 | + $conn->execute(' |
| 146 | + PRAGMA auto_vacuum = FULL; |
| 147 | + PRAGMA journal_mode = OFF; |
| 148 | + PRAGMA synchronous = OFF; |
| 149 | + PRAGMA foreign_keys = OFF; |
| 150 | + PRAGMA temp_store = MEMORY; |
| 151 | + PRAGMA automatic_index = OFF; |
| 152 | + '); |
| 153 | + |
| 154 | + if (!$this->shouldGcVacuum()) { |
| 155 | + return; |
| 156 | + } |
| 157 | + |
| 158 | + try { |
| 159 | + $conn->execute('VACUUM;'); |
| 160 | + } catch (PDOException) { |
| 161 | + // phpcs:disable |
| 162 | + @unlink(TMP . 'debug_kit.sqlite'); |
| 163 | + // phpcs:enable |
| 164 | + } |
135 | 165 | } |
136 | 166 | } catch (PDOException $e) { |
137 | 167 | Log::warning('Unable to garbage collect requests table. This is probably due to concurrent requests.'); |
|
0 commit comments