From 1fdb00fa0e768cd14e62dd42ac6e860be80f8e58 Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Tue, 13 Aug 2019 16:41:56 +0300 Subject: [PATCH] Don't add duplicate scenes,galleries to the DB --- pkg/manager/task_scan.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index 19a016e97..dfdc879ab 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -46,9 +46,15 @@ func (t *ScanTask) scanGallery() { tx := database.DB.MustBeginTx(ctx, nil) gallery, _ = qb.FindByChecksum(checksum, tx) if gallery != nil { - logger.Infof("%s already exists. Updating path...", t.FilePath) - gallery.Path = t.FilePath - _, err = qb.Update(*gallery, tx) + exists, _ := utils.FileExists(t.FilePath) + if exists { + logger.Infof("%s already exists. Duplicate of %s ", t.FilePath, gallery.Path) + } else { + + logger.Infof("%s already exists. Updating path...", t.FilePath) + gallery.Path = t.FilePath + _, err = qb.Update(*gallery, tx) + } } else { logger.Infof("%s doesn't exist. Creating new item...", t.FilePath) currentTime := time.Now() @@ -95,9 +101,14 @@ func (t *ScanTask) scanScene() { ctx := context.TODO() tx := database.DB.MustBeginTx(ctx, nil) if scene != nil { - logger.Infof("%s already exists. Updating path...", t.FilePath) - scene.Path = t.FilePath - _, err = qb.Update(*scene, tx) + exists, _ := utils.FileExists(t.FilePath) + if exists { + logger.Infof("%s already exists. Duplicate of %s ", t.FilePath, scene.Path) + } else { + logger.Infof("%s already exists. Updating path...", t.FilePath) + scene.Path = t.FilePath + _, err = qb.Update(*scene, tx) + } } else { logger.Infof("%s doesn't exist. Creating new item...", t.FilePath) currentTime := time.Now()