HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/sql/photoglide_photos.sql
-- @query photoglide_photos
-- @db media 11.0
-- @db thumbnailCache 9.0
-- @param max_photos INT
-- @with collection
-- @param collection_id TEXT
-- @end-with
-- @param taken_date_col IDEN
-- @sample taken_date_col literal:takenDateTimeNormalized
SELECT
    mp.driveItemId,
    mp.name,
    mp.?taken_date_col AS takenDateTime,
    mp.width,
    mp.height,
    tm.id AS thumbnailId,
    COALESCE(length(t.thumbnail), 0) AS thumbnailSize
FROM media.media_properties mp
LEFT JOIN thumbnailCache.thumbnail_metadata tm
    ON tm.driveItemId = mp.driveItemId
    AND (tm.imageModTime IS NULL
         OR json_extract(mp.fileSystemInfo, '$.lastModifiedDateTime') IS NULL
         OR tm.imageModTime >= CAST(strftime('%s', json_extract(mp.fileSystemInfo, '$.lastModifiedDateTime')) AS INTEGER) * 1000)
LEFT JOIN thumbnailCache.thumbnails t ON t.thumbnailMetadataRef = tm.id
WHERE mp.?taken_date_col IS NOT NULL AND mp.?taken_date_col != ''
  -- @with collection
  AND mp.driveItemId IN (
      SELECT driveItemId FROM collection_items WHERE collectionId = ?collection_id
  )
  -- @end-with
ORDER BY mp.?taken_date_col DESC
LIMIT ?max_photos