Indexing: Use fallback for MySQL to improve performance on MariaDB #599

This commit is contained in:
Michael Mayer 2020-12-09 13:08:55 +01:00
parent 5645cb1d0e
commit b7cd2facb9
2 changed files with 12 additions and 3 deletions

View file

@ -143,9 +143,10 @@ func IndexedFiles() (result FileMap, err error) {
// CleanDuplicates removes all files from the duplicates table that don't exist in the files table.
func CleanDuplicates() error {
if res := UnscopedDb().Delete(entity.Duplicate{}, "file_hash IN (SELECT file_hash FROM (SELECT d.file_hash FROM duplicates d LEFT JOIN files f ON d.file_hash = f.file_hash AND f.file_missing = 0 AND f.deleted_at IS NULL WHERE f.file_hash IS NULL) AS tmp)"); res.Error != nil {
return res.Error
if err := UnscopedDb().Delete(entity.Duplicate{}, "file_hash IN (SELECT d.file_hash FROM duplicates d LEFT JOIN files f ON d.file_hash = f.file_hash AND f.file_missing = 0 AND f.deleted_at IS NULL WHERE f.file_hash IS NULL)").Error; err == nil {
return nil
}
return nil
// MySQL fallback, see https://github.com/photoprism/photoprism/issues/599
return UnscopedDb().Delete(entity.Duplicate{}, "file_hash IN (SELECT file_hash FROM (SELECT d.file_hash FROM duplicates d LEFT JOIN files f ON d.file_hash = f.file_hash AND f.file_missing = 0 AND f.deleted_at IS NULL WHERE f.file_hash IS NULL) AS tmp)").Error
}

View file

@ -85,6 +85,14 @@ func PhotosMissing(limit int, offset int) (entities entity.Photos, err error) {
// ResetPhotoQuality resets the quality of photos without primary file to -1.
func ResetPhotoQuality() error {
if err := Db().Table("photos").
Where("id IN (SELECT photos.id FROM photos LEFT JOIN files ON photos.id = files.photo_id AND files.file_primary = 1 WHERE files.id IS NULL GROUP BY photos.id)").
Where("id IN (SELECT id FROM (SELECT photos.id FROM photos LEFT JOIN files ON photos.id = files.photo_id AND files.file_primary = 1 WHERE files.id IS NULL GROUP BY photos.id) AS tmp)").
Update("photo_quality", -1).Error; err == nil {
return nil
}
// MySQL fallback, see https://github.com/photoprism/photoprism/issues/599
return Db().Table("photos").
Where("id IN (SELECT id FROM (SELECT photos.id FROM photos LEFT JOIN files ON photos.id = files.photo_id AND files.file_primary = 1 WHERE files.id IS NULL GROUP BY photos.id) AS tmp)").
Update("photo_quality", -1).Error