From 783e8ec3af22288cd115f8091997a2af2f2704d9 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 27 Apr 2020 17:06:36 +0200 Subject: [PATCH] Backend: Don't use private photos as cover for labels or albums Signed-off-by: Michael Mayer --- assets/resources/examples/fixtures.sql | 12 ++++++------ internal/query/album.go | 2 +- internal/query/label.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/assets/resources/examples/fixtures.sql b/assets/resources/examples/fixtures.sql index de316887f..8f3c23de7 100644 --- a/assets/resources/examples/fixtures.sql +++ b/assets/resources/examples/fixtures.sql @@ -16,12 +16,12 @@ INSERT INTO files (id, photo_id, photo_uuid, file_uuid, file_name, file_primary, INSERT INTO files (id, photo_id, photo_uuid, file_uuid, file_name, file_primary, file_hash, file_missing) VALUES (3, '2', '655', 'fq8ev8t1x0bwje4e', 'exampleXmpFile.xmp', 0, '125xxx', 0); INSERT INTO files (id, photo_id, photo_uuid, file_uuid, file_name, file_primary, file_hash, file_missing) VALUES (4, '5', '658', 'fq8ev9c3sp88uwzq', 'bridge.jpg', 1, '126xxx', 0); INSERT INTO files (id, photo_id, photo_uuid, file_uuid, file_name, file_primary, file_hash, file_missing) VALUES (5, '6', '659', 'fq8evan3urz3i48d', 'reunion.jpg', 1, '127xxx', 0); -INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES (1, '654', 2790, 2, 48.519234, 9.057997); -INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES (2, '655', 2790, 2, 48.519234, 9.057997); -INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES (3, '656', 1990, 3, 48.519234, 9.057997); -INSERT INTO photos (id, photo_uuid, photo_year, photo_month, photo_lat, photo_lng) VALUES (4, '657', 1990, 4, 48.519234, 9.057997); -INSERT INTO photos (id, photo_uuid, taken_at, photo_lat, photo_lng, photo_title) VALUES (5, '658', '2014-07-17 15:42:12', 48.519235, 9.05799666, 'Neckarbrücke'); -INSERT INTO photos (id, photo_uuid, taken_at, photo_lat, photo_lng, photo_title) VALUES (6, '659', '2015-11-11 09:07:18', -21.342636, 55.466944, 'Reunion'); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, photo_year, photo_month, photo_lat, photo_lng) VALUES (1, '654', 0, 3, 2790, 2, 48.519234, 9.057997); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, photo_year, photo_month, photo_lat, photo_lng) VALUES (2, '655', 0, 3, 2790, 2, 48.519234, 9.057997); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, photo_year, photo_month, photo_lat, photo_lng) VALUES (3, '656', 0, 3, 1990, 3, 48.519234, 9.057997); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, photo_year, photo_month, photo_lat, photo_lng) VALUES (4, '657', 0, 3, 1990, 4, 48.519234, 9.057997); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, taken_at, photo_lat, photo_lng, photo_title) VALUES (5, '658', 0, 3, '2014-07-17 15:42:12', 48.519235, 9.05799666, 'Neckarbrücke'); +INSERT INTO photos (id, photo_uuid, photo_private, photo_quality, taken_at, photo_lat, photo_lng, photo_title) VALUES (6, '659', 0, 3, '2015-11-11 09:07:18', -21.342636, 55.466944, 'Reunion'); INSERT INTO keywords (id, keyword, skip) VALUES (1, 'bridge', 0); INSERT INTO keywords (id, keyword, skip) VALUES (2, 'beach', 0); INSERT INTO photos_keywords (photo_id, keyword_id) VALUES (5, 1); diff --git a/internal/query/album.go b/internal/query/album.go index 6699d6ac7..761f2b1e0 100644 --- a/internal/query/album.go +++ b/internal/query/album.go @@ -42,7 +42,7 @@ func (q *Query) AlbumThumbByUUID(albumUUID string) (file entity.File, err error) 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"). + Joins("JOIN photos ON photos.id = files.photo_id AND photos.photo_private = 0 AND photos.deleted_at IS NULL"). Order("photos.photo_quality DESC, photos.taken_at DESC"). First(&file).Error; err != nil { return file, err diff --git a/internal/query/label.go b/internal/query/label.go index 66ca981aa..1db2c2cda 100644 --- a/internal/query/label.go +++ b/internal/query/label.go @@ -61,7 +61,7 @@ func (q *Query) LabelThumbBySlug(labelSlug string) (file entity.File, err error) if err := q.db.Where("files.file_primary AND files.deleted_at IS NULL"). Joins("JOIN labels ON labels.label_slug = ?", labelSlug). Joins("JOIN photos_labels ON photos_labels.label_id = labels.id AND photos_labels.photo_id = files.photo_id"). - Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL"). + Joins("JOIN photos ON photos.id = files.photo_id AND photos.photo_private = 0 AND photos.deleted_at IS NULL"). Order("photos.photo_quality DESC, photos_labels.uncertainty ASC"). First(&file).Error; err != nil { return file, err @@ -76,7 +76,7 @@ func (q *Query) LabelThumbByUUID(labelUUID string) (file entity.File, err error) err = q.db.Where("files.file_primary AND files.deleted_at IS NULL"). Joins("JOIN labels ON labels.label_uuid = ?", labelUUID). Joins("JOIN photos_labels ON photos_labels.label_id = labels.id AND photos_labels.photo_id = files.photo_id"). - Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL"). + Joins("JOIN photos ON photos.id = files.photo_id AND photos.photo_private = 0 AND photos.deleted_at IS NULL"). Order("photos.photo_quality DESC, photos_labels.uncertainty ASC"). First(&file).Error @@ -89,7 +89,7 @@ func (q *Query) LabelThumbByUUID(labelUUID string) (file entity.File, err error) Joins("JOIN photos_labels ON photos_labels.photo_id = files.photo_id"). Joins("JOIN categories c ON photos_labels.label_id = c.label_id"). Joins("JOIN labels ON c.category_id = labels.id AND labels.label_uuid= ?", labelUUID). - Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL"). + Joins("JOIN photos ON photos.id = files.photo_id AND photos.photo_private = 0 AND photos.deleted_at IS NULL"). Order("photos.photo_quality DESC, photos_labels.uncertainty ASC"). First(&file).Error