Compare commits

...
2 Commits
Author SHA1 Message Date
Lewis Dale 519611d06b Fix it again 2023-08-27 22:12:28 +01:00
Lewis Dale a0580ad085 Enforce uniqueness 2023-08-27 22:03:56 +01:00
3 changed files with 14 additions and 5 deletions

No files matched your search

+1
View File
@@ -48,6 +48,7 @@ class Resizer
private function createVariant(Image $original, ResizeParams $params): string private function createVariant(Image $original, ResizeParams $params): string
{ {
$quality = $params->quality ?: -1; $quality = $params->quality ?: -1;
$this->logger->info("Resizing image", ['params'=>$params]);
$original->toWidth($params->width ?? intval($_ENV["DEFAULT_WIDTH"])); $original->toWidth($params->width ?? intval($_ENV["DEFAULT_WIDTH"]));
+12 -4
View File
@@ -24,6 +24,9 @@ class SqliteImageDb implements ImageDb {
quality INTEGER NULLABLE, quality INTEGER NULLABLE,
content TEXT NOT NULL content TEXT NOT NULL
)'); )');
// Create a unique index on the path and params
$this->db->exec('CREATE UNIQUE INDEX IF NOT EXISTS images_path_width_height_quality ON images (path, width, height, quality)');
} }
public function findImage(string $path, ResizeParams $params): Image | null { public function findImage(string $path, ResizeParams $params): Image | null {
@@ -33,10 +36,15 @@ class SqliteImageDb implements ImageDb {
$query .= $params->quality ? ' AND quality = :quality' : ' AND quality IS NULL'; $query .= $params->quality ? ' AND quality = :quality' : ' AND quality IS NULL';
$stmt = $this->db->prepare($query); $stmt = $this->db->prepare($query);
$stmt->bindParam(':path', $path);
if ($params->width !== null) $stmt->bindParam(':width', $params->width); $queryParams = [
if ($params->height !== null) $stmt->bindParam(':height', $params->height); ':path' => $path,
if ($params->quality !== null) $stmt->bindParam(':quality', $params->quality); ];
if ($params->width !== null) $queryParams[':width'] = $params->width;
if ($params->height !== null) $queryParams[':height'] = $params->height;
if ($params->quality !== null) $queryParams[':quality'] = $params->quality;
$stmt->execute($queryParams);
$this->logger->info("Querying images", ['query' => $stmt->queryString]); $this->logger->info("Querying images", ['query' => $stmt->queryString]);
+1 -1
View File
@@ -12,7 +12,7 @@ class ResizeParams
public function __construct(array $params) public function __construct(array $params)
{ {
$this->width = intval($params['width']) ?: intval($_ENV["DEFAULT_WIDTH"]); $this->width = isset($params['width']) ? intval($params['width']) : intval($_ENV["DEFAULT_WIDTH"]);
$this->height = intval($params['height']) ?: null; $this->height = intval($params['height']) ?: null;
$this->quality = isset($params['quality']) ? intval($params['quality']) : null; $this->quality = isset($params['quality']) ? intval($params['quality']) : null;
} }