From bb0fb1daddc7bee4cb3002a4f446fb8f062d029a Mon Sep 17 00:00:00 2001 From: Richard Dern Date: Thu, 9 May 2024 23:22:40 +0200 Subject: [PATCH] Avoid some disk writes with checksums --- app/Console/Commands/Bundle/Render.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Console/Commands/Bundle/Render.php b/app/Console/Commands/Bundle/Render.php index fa4d1cd..059bb98 100644 --- a/app/Console/Commands/Bundle/Render.php +++ b/app/Console/Commands/Bundle/Render.php @@ -189,6 +189,18 @@ private function renderFeed(): self foreach ($result as $path => $content) { $this->output->write(sprintf('Rendering %s as feed... ', $path)); + + if ($this->targetDisk->exists($path)) { + $fileChecksum = $this->targetDisk->checksum($path); + $contentChecksum = md5($content); + + if ($fileChecksum === $contentChecksum) { + $this->info('Not changed'); + + continue; + } + } + $this->targetDisk->put($path, $content); $this->info('OK'); } @@ -230,6 +242,15 @@ private function handleBundle(Bundle $bundle, $progress) $path = Str::finish($path, '/') . 'index.html'; } + if ($this->targetDisk->exists($path)) { + $fileChecksum = $this->targetDisk->checksum($path); + $contentChecksum = md5($content); + + if ($fileChecksum !== $contentChecksum) { + continue; + } + } + $this->targetDisk->put($path, $content); } }