From f53e9887e2f46bcefb2d61c65c5171cd16d67306 Mon Sep 17 00:00:00 2001 From: Sergio Mendolia Date: Fri, 1 Sep 2023 14:38:54 +0200 Subject: [PATCH] Faster checksum calculation --- src/Service/BookFileSystemManager.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Service/BookFileSystemManager.php b/src/Service/BookFileSystemManager.php index a5e5bec0..acaf2464 100644 --- a/src/Service/BookFileSystemManager.php +++ b/src/Service/BookFileSystemManager.php @@ -18,6 +18,8 @@ class BookFileSystemManager '*.epub','*.cbr','*.cbz','*.pdf','*.mobi' ]; + public const CHUNK = 65536; + public KernelInterface $appKernel; private SluggerInterface $slugger; @@ -100,10 +102,14 @@ public function getCoverFile(Book $book): ?SplFileInfo */ public function getFileChecksum(SplFileInfo $file): string { - $checkSum = sha1_file($file->getRealPath()); - if($checkSum===false){ - throw new \RuntimeException('Could not calculate file Checksum'); + $checkSum = shell_exec('sha1sum -b ' . escapeshellarg($file->getRealPath())); + + if ($checkSum === null || $checkSum === false) { + throw new RuntimeException('Could not calculate file Checksum'); } + + [$checkSum,] = explode(' ', $checkSum); + return $checkSum; }