Index: Improve query for photos with missing primaries #1010

This commit is contained in:
Michael Mayer 2021-02-08 07:39:29 +01:00
parent 84ab1bc575
commit 568685f991
3 changed files with 5 additions and 5 deletions

View file

@ -1182,9 +1182,9 @@ func (m *Photo) SetPrimary(fileUID string) error {
return fmt.Errorf("file uid is empty")
}
Db().Model(File{}).Where("photo_uid = ? AND file_uid <> ?", m.PhotoUID, fileUID).UpdateColumn("file_primary", false)
Db().Model(File{}).Where("photo_uid = ? AND file_uid <> ?", m.PhotoUID, fileUID).UpdateColumn("file_primary", 0)
if err := Db().Model(File{}).Where("photo_uid = ? AND file_uid = ?", m.PhotoUID, fileUID).UpdateColumn("file_primary", true).Error; err != nil {
if err := Db().Model(File{}).Where("photo_uid = ? AND file_uid = ?", m.PhotoUID, fileUID).UpdateColumn("file_primary", 1).Error; err != nil {
return err
} else if m.PhotoQuality < 0 {
m.PhotoQuality = 0

View file

@ -123,8 +123,8 @@ func SetPhotoPrimary(photoUID, fileUID string) error {
return fmt.Errorf("file uid is missing")
}
Db().Model(entity.File{}).Where("photo_uid = ? AND file_uid <> ?", photoUID, fileUID).UpdateColumn("file_primary", false)
return Db().Model(entity.File{}).Where("photo_uid = ? AND file_uid = ?", photoUID, fileUID).UpdateColumn("file_primary", true).Error
Db().Model(entity.File{}).Where("photo_uid = ? AND file_uid <> ?", photoUID, fileUID).UpdateColumn("file_primary", 0)
return Db().Model(entity.File{}).Where("photo_uid = ? AND file_uid = ?", photoUID, fileUID).UpdateColumn("file_primary", 1).Error
}
// SetFileError updates the file error column.

View file

@ -137,7 +137,7 @@ func FixPrimaries() error {
if err := UnscopedDb().
Raw(`SELECT * FROM photos WHERE
deleted_at IS NULL
AND id NOT IN (SELECT photo_id FROM files WHERE file_primary = true)`).
AND id NOT IN (SELECT photo_id FROM files WHERE file_primary = 1)`).
Find(&photos).Error; err != nil {
return err
}