From f21e77c68260f0294b39b9355ae363f5a223975b Mon Sep 17 00:00:00 2001 From: andrea Date: Wed, 12 Jul 2023 15:57:10 +0200 Subject: [PATCH] Re-index only if quiz hash as changed --- store/file/file.go | 17 +++++++++-------- store/file/file_test.go | 1 + store/memory/memory.go | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/store/file/file.go b/store/file/file.go index 2255788..c1eeff2 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -119,16 +119,17 @@ func (s *FileProboCollectorStore) UpdateQuiz(r *client.CreateUpdateQuizRequest, return nil, err } - err = s.createOrUpdateMarkdownFile(quiz) - if err != nil { - return nil, err - } + if id != quiz.ID { // Update and re-index only if quiz hash is changed + err = s.createOrUpdateMarkdownFile(quiz) + if err != nil { + return nil, err + } - err = s.Reindex() - if err != nil { - return nil, err + err = s.Reindex() + if err != nil { + return nil, err + } } - return s.memoryStore.ReadQuizByHash(quiz.Hash) } diff --git a/store/file/file_test.go b/store/file/file_test.go index 2897b43..36ddd06 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -187,6 +187,7 @@ func (t *testSuite) TestUpdateQuiz() { }, quiz.ID) t.Nil(err, fmt.Sprintf("Quiz should be updated without errors: %v", err)) + // t.Equal(updatedQuiz.ID, quiz.ID, "Quiz ID should remain the same") if !t.Failed() { path, err := store.GetPath(updatedQuiz) diff --git a/store/memory/memory.go b/store/memory/memory.go index f922d9b..59b8a04 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -149,7 +149,7 @@ func (s *MemoryProboCollectorStore) createOrUpdateQuiz(r *client.CreateUpdateQui if id != "" { quiz = s.getQuizFromID(id) - if quiz == nil { // Quiz is already present in the store + if quiz == nil { // Quiz is not present in the store return nil, fmt.Errorf("Quiz ID %v doesn't exist in the store!", id) } } else {