From e2cf30a307950b44700be0f5102ffa28540f384f Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Sun, 27 Aug 2023 22:01:43 +0100 Subject: [PATCH] Actually fix the query and caching --- src/Lib/SqliteImageDb.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Lib/SqliteImageDb.php b/src/Lib/SqliteImageDb.php index 1e9cdc2..e25a0a8 100644 --- a/src/Lib/SqliteImageDb.php +++ b/src/Lib/SqliteImageDb.php @@ -27,21 +27,21 @@ class SqliteImageDb implements ImageDb { } public function findImage(string $path, ResizeParams $params): Image | null { - $query = "SELECT * FROM images WHERE path = :path"; - $query .= $params->width ? " AND width = :width" : " AND width IS NULL"; - $query .= $params->height ? " AND height = :height" : " AND height IS NULL"; - $query .= $params->quality ? " AND quality = :quality" : " AND quality IS NULL"; + $query = 'SELECT * FROM images WHERE path = :path'; + $query .= $params->width ? ' AND width = :width' : ' AND width IS NULL'; + $query .= $params->height ? ' AND height = :height' : ' AND height IS NULL'; + $query .= $params->quality ? ' AND quality = :quality' : ' AND quality IS NULL'; $stmt = $this->db->prepare($query); - $stmt->execute([ - ':path' => $path, - ':width' => $params->width, - ':height' => $params->height, - ':quality' => $params->quality - ]); + $stmt->bindParam(':path', $path); + if ($params->width !== null) $stmt->bindParam(':width', $params->width); + if ($params->height !== null) $stmt->bindParam(':height', $params->height); + if ($params->quality !== null) $stmt->bindParam(':quality', $params->quality); $this->logger->info("Querying images", ['query' => $stmt->queryString]); + $stmt->execute(); + $result = $stmt->fetchObject(); return $result ? Image::fromString(base64_decode($result->content)) : null;