Library: Add option to run index and cache cleanup from the UI #3699

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2023-09-03 16:02:42 +02:00
parent ec1e3f0fb6
commit 0e4ce95ff1
48 changed files with 163 additions and 105 deletions

View File

@@ -71,6 +71,7 @@ func indexAction(ctx *cli.Context) error {
var found fs.Done
var indexed int
// Update file index.
if w := get.Index(); w != nil {
indexStart := time.Now()
convert := conf.Settings().Index.Convert && conf.SidecarWritable()
@@ -81,14 +82,17 @@ func indexAction(ctx *cli.Context) error {
log.Infof("index: updated %s [%s]", english.Plural(indexed, "file", "files"), time.Since(indexStart))
}
// Remove missing files from search results.
if w := get.Purge(); w != nil {
purgeStart := time.Now()
// Purge worker options.
opt := photoprism.PurgeOptions{
Path: subPath,
Ignore: found,
Force: ctx.Bool("force") || ctx.Bool("cleanup") || indexed > 0,
}
// Start purge.
purgeStart := time.Now()
if files, photos, updated, err := w.Start(opt); err != nil {
log.Error(err)
} else if updated > 0 {
@@ -96,19 +100,22 @@ func indexAction(ctx *cli.Context) error {
}
}
// Delete orphaned index entries, sidecar files and thumbnails?
if ctx.Bool("cleanup") {
cleanupStart := time.Now()
// Get cleanup worker instance.
w := get.CleanUp()
// Cleanup worker options.
opt := photoprism.CleanUpOptions{
Dry: false,
}
// Start cleanup worker.
// Start index and cache cleanup.
cleanupStart := time.Now()
if thumbnails, _, sidecars, err := w.Start(opt); err != nil {
return err
} else if total := thumbnails + sidecars; total > 0 {
log.Infof("cleanup: removed %s in total [%s]", english.Plural(total, "file", "files"), time.Since(cleanupStart))
log.Infof("cleanup: deleted %s in total [%s]", english.Plural(total, "file", "files"), time.Since(cleanupStart))
}
}