Albums: Disable date update queries on SQLite #692
This commit is contained in:
parent
c0fb3deb06
commit
0d16e31154
4 changed files with 40 additions and 14 deletions
|
@ -181,11 +181,16 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) {
|
|||
|
||||
// UpdateAlbumDates updates album year, month and day based on indexed photo metadata.
|
||||
func UpdateAlbumDates() error {
|
||||
return UnscopedDb().Exec(`UPDATE albums
|
||||
INNER JOIN
|
||||
(SELECT photo_path, MAX(taken_at_local) AS taken_max
|
||||
FROM photos WHERE taken_src = 'meta' AND photos.photo_quality >= 3 AND photos.deleted_at IS NULL
|
||||
GROUP BY photo_path) AS p ON albums.album_path = p.photo_path
|
||||
SET albums.album_year = YEAR(taken_max), albums.album_month = MONTH(taken_max), albums.album_day = DAY(taken_max)
|
||||
WHERE albums.album_type = 'folder' AND albums.album_path IS NOT NULL AND p.taken_max IS NOT NULL`).Error
|
||||
switch DbDialect() {
|
||||
case MySQL:
|
||||
return UnscopedDb().Exec(`UPDATE albums
|
||||
INNER JOIN
|
||||
(SELECT photo_path, MAX(taken_at_local) AS taken_max
|
||||
FROM photos WHERE taken_src = 'meta' AND photos.photo_quality >= 3 AND photos.deleted_at IS NULL
|
||||
GROUP BY photo_path) AS p ON albums.album_path = p.photo_path
|
||||
SET albums.album_year = YEAR(taken_max), albums.album_month = MONTH(taken_max), albums.album_day = DAY(taken_max)
|
||||
WHERE albums.album_type = 'folder' AND albums.album_path IS NOT NULL AND p.taken_max IS NOT NULL`).Error
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,3 +195,11 @@ func TestAlbumSearch(t *testing.T) {
|
|||
assert.Equal(t, 0, len(result))
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateAlbumDates(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
if err := UpdateAlbumDates(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
|
@ -49,11 +49,16 @@ func AlbumFolders(threshold int) (folders entity.Folders, err error) {
|
|||
|
||||
// UpdateFolderDates updates folder year, month and day based on indexed photo metadata.
|
||||
func UpdateFolderDates() error {
|
||||
return UnscopedDb().Exec(`UPDATE folders
|
||||
INNER JOIN
|
||||
(SELECT photo_path, MAX(taken_at_local) AS taken_max
|
||||
FROM photos WHERE taken_src = 'meta' AND photos.photo_quality >= 3 AND photos.deleted_at IS NULL
|
||||
GROUP BY photo_path) AS p ON folders.path = p.photo_path
|
||||
SET folders.folder_year = YEAR(taken_max), folders.folder_month = MONTH(taken_max), folders.folder_day = DAY(taken_max)
|
||||
WHERE p.taken_max IS NOT NULL`).Error
|
||||
switch DbDialect() {
|
||||
case MySQL:
|
||||
return UnscopedDb().Exec(`UPDATE folders
|
||||
INNER JOIN
|
||||
(SELECT photo_path, MAX(taken_at_local) AS taken_max
|
||||
FROM photos WHERE taken_src = 'meta' AND photos.photo_quality >= 3 AND photos.deleted_at IS NULL
|
||||
GROUP BY photo_path) AS p ON folders.path = p.photo_path
|
||||
SET folders.folder_year = YEAR(taken_max), folders.folder_month = MONTH(taken_max), folders.folder_day = DAY(taken_max)
|
||||
WHERE p.taken_max IS NOT NULL`).Error
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,3 +45,11 @@ func TestAlbumFolders(t *testing.T) {
|
|||
t.Logf("folders: %+v", folders)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateFolderDates(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
if err := UpdateFolderDates(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue