From f14752f08c720fad54bcb978b9d0ec508b96b8a2 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sat, 23 Jul 2022 11:20:56 +0200 Subject: [PATCH] Purge: Improve tests and logs for RegenerateIndex() #2540 Signed-off-by: Michael Mayer --- internal/entity/file.go | 8 ++++---- internal/entity/file_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/entity/file.go b/internal/entity/file.go index e093dba14..884dcce4a 100644 --- a/internal/entity/file.go +++ b/internal/entity/file.go @@ -115,16 +115,16 @@ func (m File) RegenerateIndex() { if m.PhotoID > 0 { updateWhere = gorm.Expr("files.photo_id = ?", m.PhotoID) - scope = "partial file index" + scope = "index by photo id" } else if m.PhotoUID != "" { updateWhere = gorm.Expr("files.photo_uid = ?", m.PhotoUID) - scope = "partial file index" + scope = "index by photo uid" } else if m.ID > 0 { updateWhere = gorm.Expr("files.id = ?", m.ID) - scope = "partial file index" + scope = "index by file id" } else { updateWhere = gorm.Expr("files.photo_id IS NOT NULL") - scope = "file index" + scope = "index" } switch DbDialect() { diff --git a/internal/entity/file_test.go b/internal/entity/file_test.go index d948e16c5..1c1b3f54b 100644 --- a/internal/entity/file_test.go +++ b/internal/entity/file_test.go @@ -14,6 +14,15 @@ import ( ) func TestFile_RegenerateIndex(t *testing.T) { + t.Run("ID", func(t *testing.T) { + File{ID: 1000000}.RegenerateIndex() + }) + t.Run("PhotoID", func(t *testing.T) { + File{PhotoID: 1000039}.RegenerateIndex() + }) + t.Run("PhotoUID", func(t *testing.T) { + File{PhotoUID: "pr2xu7myk7wrbk32"}.RegenerateIndex() + }) t.Run("FirstFileByHash", func(t *testing.T) { f, err := FirstFileByHash("2cad9168fa6acc5c5c2965ddf6ec465ca42fd818") if err != nil { @@ -21,6 +30,9 @@ func TestFile_RegenerateIndex(t *testing.T) { } f.RegenerateIndex() }) + t.Run("All", func(t *testing.T) { + File{}.RegenerateIndex() + }) } func TestFirstFileByHash(t *testing.T) {