|
16 | 16 |
|
17 | 17 | use Cake\Core\Configure; |
18 | 18 | use Cake\Database\Driver\Sqlite; |
| 19 | +use Cake\Log\Log; |
19 | 20 | use Cake\ORM\Query; |
20 | 21 | use Cake\ORM\Table; |
| 22 | +use PDOException; |
21 | 23 |
|
22 | 24 | /** |
23 | 25 | * The requests table tracks basic information about each request. |
@@ -100,30 +102,36 @@ public function gc() |
100 | 102 | if (!$this->shouldGc()) { |
101 | 103 | return; |
102 | 104 | } |
103 | | - $noPurge = $this->find() |
104 | | - ->select(['id']) |
105 | | - ->enableHydration(false) |
106 | | - ->order(['requested_at' => 'desc']) |
107 | | - ->limit(Configure::read('DebugKit.requestCount') ?: 20) |
108 | | - ->extract('id') |
109 | | - ->toArray(); |
110 | 105 |
|
111 | | - $query = $this->Panels->query() |
112 | | - ->delete() |
113 | | - ->where(['request_id NOT IN' => $noPurge]); |
114 | | - $statement = $query->execute(); |
115 | | - $statement->closeCursor(); |
| 106 | + try { |
| 107 | + $noPurge = $this->find() |
| 108 | + ->select(['id']) |
| 109 | + ->enableHydration(false) |
| 110 | + ->order(['requested_at' => 'desc']) |
| 111 | + ->limit(Configure::read('DebugKit.requestCount') ?: 20) |
| 112 | + ->extract('id') |
| 113 | + ->toArray(); |
116 | 114 |
|
117 | | - $query = $this->query() |
118 | | - ->delete() |
119 | | - ->where(['id NOT IN' => $noPurge]); |
| 115 | + $query = $this->Panels->query() |
| 116 | + ->delete() |
| 117 | + ->where(['request_id NOT IN' => $noPurge]); |
| 118 | + $statement = $query->execute(); |
| 119 | + $statement->closeCursor(); |
120 | 120 |
|
121 | | - $statement = $query->execute(); |
122 | | - $statement->closeCursor(); |
| 121 | + $query = $this->query() |
| 122 | + ->delete() |
| 123 | + ->where(['id NOT IN' => $noPurge]); |
123 | 124 |
|
124 | | - $conn = $this->getConnection(); |
125 | | - if ($conn->getDriver() instanceof Sqlite) { |
126 | | - $conn->execute('VACUUM;'); |
| 125 | + $statement = $query->execute(); |
| 126 | + $statement->closeCursor(); |
| 127 | + |
| 128 | + $conn = $this->getConnection(); |
| 129 | + if ($conn->getDriver() instanceof Sqlite) { |
| 130 | + $conn->execute('VACUUM;'); |
| 131 | + } |
| 132 | + } catch (PDOException $e) { |
| 133 | + Log::warning('Unable to garbage collect requests table. This is probably due to concurrent requests.'); |
| 134 | + Log::warning((string)$e); |
127 | 135 | } |
128 | 136 | } |
129 | 137 | } |
0 commit comments