Performance: Don't save all albums when the background worker runs #2705

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-09-14 22:00:20 +02:00
parent a1642fcfab
commit 7f70772d86
4 changed files with 18 additions and 10 deletions

View file

@ -12,14 +12,14 @@ import (
// BackupAlbums creates a YAML file backup of all albums.
func BackupAlbums(backupPath string, force bool) (count int, result error) {
c := Config()
if !c.BackupYaml() && !force {
log.Debugf("backup: album yaml files disabled")
return count, nil
}
albums, err := query.Albums(0, 9999)
albums, err := query.Albums(0, 1000000)
if err != nil {
return count, err

View file

@ -3,6 +3,7 @@ package photoprism
import (
"fmt"
"math"
"path/filepath"
"runtime/debug"
"strconv"
@ -14,6 +15,7 @@ import (
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
)
// Moments represents a worker that creates albums based on popular locations, dates and labels.
@ -82,7 +84,7 @@ func (w *Moments) Start() (err error) {
return nil
}
// Important folders.
// Create an album for each folder that contains originals.
if results, err := query.AlbumFolders(1); err != nil {
log.Errorf("moments: %s", err.Error())
} else {
@ -116,7 +118,7 @@ func (w *Moments) Start() (err error) {
}
}
// All years and months.
// Create an album for each month and year.
if results, err := query.MomentsTime(1, w.conf.Settings().Features.Private); err != nil {
log.Errorf("moments: %s", err.Error())
} else {
@ -143,7 +145,7 @@ func (w *Moments) Start() (err error) {
}
}
// Countries by year.
// Create moments based on country and year.
if results, err := query.MomentsCountries(threshold, w.conf.Settings().Features.Private); err != nil {
log.Errorf("moments: %s", err.Error())
} else {
@ -178,7 +180,7 @@ func (w *Moments) Start() (err error) {
}
}
// States and countries.
// Create moments based on states and countries.
if results, err := query.MomentsStates(1, w.conf.Settings().Features.Private); err != nil {
log.Errorf("moments: %s", err.Error())
} else {
@ -215,7 +217,7 @@ func (w *Moments) Start() (err error) {
}
}
// Popular labels.
// Create moments based on related image classifications.
if results, err := query.MomentsLabels(threshold, w.conf.Settings().Features.Private); err != nil {
log.Errorf("moments: %s", err.Error())
} else {
@ -254,15 +256,21 @@ func (w *Moments) Start() (err error) {
}
}
// UpdateFolderDates updates folder year, month and day based on indexed photo metadata.
if err := query.UpdateFolderDates(); err != nil {
log.Errorf("moments: %s (update folder dates)", err.Error())
}
// UpdateAlbumDates updates the year, month and day of the album based on the indexed photo metadata.
if err := query.UpdateAlbumDates(); err != nil {
log.Errorf("moments: %s (update album dates)", err.Error())
}
if count, err := BackupAlbums(w.conf.AlbumsPath(), false); err != nil {
// Make sure that the albums have been backed up before, otherwise back up all albums.
if fs.PathExists(filepath.Join(w.conf.AlbumsPath(), entity.AlbumDefault)) &&
fs.PathExists(filepath.Join(w.conf.AlbumsPath(), entity.AlbumMonth)) {
// Skip.
} else if count, err := BackupAlbums(w.conf.AlbumsPath(), false); err != nil {
log.Errorf("moments: %s (backup albums)", err.Error())
} else if count > 0 {
log.Debugf("moments: %d albums saved as yaml files", count)

View file

@ -86,7 +86,7 @@ func AlbumCoverByUID(uid string, public bool) (file entity.File, err error) {
return file, nil
}
// UpdateAlbumDates updates album year, month and day based on indexed photo metadata.
// UpdateAlbumDates updates the year, month and day of the album based on the indexed photo metadata.
func UpdateAlbumDates() error {
mutex.Index.Lock()
defer mutex.Index.Unlock()

View file

@ -68,7 +68,7 @@ func AlbumFolders(threshold int) (folders entity.Folders, err error) {
return folders, nil
}
// UpdateFolderDates updates folder year, month and day based on indexed photo metadata.
// UpdateFolderDates updates the year, month and day of the folder based on the indexed photo metadata.
func UpdateFolderDates() error {
mutex.Index.Lock()
defer mutex.Index.Unlock()