Labels: Use most probable photo with best quality as cover

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-27 14:32:15 +02:00
parent d5490c0364
commit d6dc411a88

View File

@ -58,12 +58,11 @@ func (q *Query) LabelByUUID(labelUUID string) (label entity.Label, err error) {
// LabelThumbBySlug returns a label preview file based on the slug name.
func (q *Query) LabelThumbBySlug(labelSlug string) (file entity.File, err error) {
// q.db.LogMode(true)
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").
Order("photos_labels.uncertainty ASC").
Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL").
Order("photos.photo_quality DESC, photos_labels.uncertainty ASC").
First(&file).Error; err != nil {
return file, err
}