From d5490c036468729bb9b7994e634f10ca7b3df9c0 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 27 Apr 2020 14:25:04 +0200 Subject: [PATCH] Albums: Use most recent photo with best quality as cover Signed-off-by: Michael Mayer --- internal/query/album.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/query/album.go b/internal/query/album.go index 9ad80d818..6699d6ac7 100644 --- a/internal/query/album.go +++ b/internal/query/album.go @@ -39,11 +39,11 @@ func (q *Query) AlbumByUUID(albumUUID string) (album entity.Album, err error) { // AlbumThumbByUUID returns a album preview file based on the uuid. func (q *Query) AlbumThumbByUUID(albumUUID string) (file entity.File, err error) { - // q.db.LogMode(true) - - if err := q.db.Where("files.file_primary AND files.deleted_at IS NULL"). + if err := q.db.Where("files.file_primary = 1 AND files.deleted_at IS NULL"). Joins("JOIN albums ON albums.album_uuid = ?", albumUUID). Joins("JOIN photos_albums pa ON pa.album_uuid = albums.album_uuid AND pa.photo_uuid = files.photo_uuid"). + Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL"). + Order("photos.photo_quality DESC, photos.taken_at DESC"). First(&file).Error; err != nil { return file, err }