Skip to content

Commit fcd4ae7

Browse files
committed
Apply fixed Coderabbitai review.
1 parent 60c174e commit fcd4ae7

2 files changed

Lines changed: 233 additions & 30 deletions

File tree

‎src/Storage/SnapshotStore.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ public function writeSnapshot(DebugSnapshot $snapshot, int $historySize): array
190190

191191
$removed = $this->collectGarbage($entries, $historySize);
192192

193-
$this->atomicWrite($snapshotFile, $snapshotJson);
193+
if ($historySize > 0) {
194+
$this->atomicWrite($snapshotFile, $snapshotJson);
195+
}
196+
194197
$this->atomicWrite($this->indexFile(), self::encode(new Manifest($entries)));
195198

196-
if ($resetStorage) {
199+
if ($removed !== [] || $resetStorage) {
197200
$this->removeStaleSnapshots($entries);
198201
}
199202

@@ -294,7 +297,7 @@ private function atomicWrite(string $file, string $contents): void
294297
*/
295298
private function collectGarbage(array &$entries, int $historySize): array
296299
{
297-
if (count($entries) <= $historySize + 10) {
300+
if (count($entries) <= $historySize) {
298301
return [];
299302
}
300303

@@ -305,16 +308,13 @@ private function collectGarbage(array &$entries, int $historySize): array
305308
foreach (array_keys($entries) as $tag) {
306309
$removed[] = $entries[$tag];
307310

308-
@unlink($this->snapshotFile($tag));
309311
unset($entries[$tag]);
310312

311313
if (--$remaining <= 0) {
312314
break;
313315
}
314316
}
315317

316-
$this->removeStaleSnapshots($entries);
317-
318318
return $removed;
319319
}
320320

0 commit comments

Comments
 (0)