Re-index only if quiz hash as changed

This commit is contained in:
andrea 2023-07-12 15:57:10 +02:00
parent 7f4849c575
commit f21e77c682
3 changed files with 11 additions and 9 deletions

View file

@ -119,16 +119,17 @@ func (s *FileProboCollectorStore) UpdateQuiz(r *client.CreateUpdateQuizRequest,
return nil, err return nil, err
} }
err = s.createOrUpdateMarkdownFile(quiz) if id != quiz.ID { // Update and re-index only if quiz hash is changed
if err != nil { err = s.createOrUpdateMarkdownFile(quiz)
return nil, err if err != nil {
} return nil, err
}
err = s.Reindex() err = s.Reindex()
if err != nil { if err != nil {
return nil, err return nil, err
}
} }
return s.memoryStore.ReadQuizByHash(quiz.Hash) return s.memoryStore.ReadQuizByHash(quiz.Hash)
} }

View file

@ -187,6 +187,7 @@ func (t *testSuite) TestUpdateQuiz() {
}, quiz.ID) }, quiz.ID)
t.Nil(err, fmt.Sprintf("Quiz should be updated without errors: %v", err)) 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() { if !t.Failed() {
path, err := store.GetPath(updatedQuiz) path, err := store.GetPath(updatedQuiz)

View file

@ -149,7 +149,7 @@ func (s *MemoryProboCollectorStore) createOrUpdateQuiz(r *client.CreateUpdateQui
if id != "" { if id != "" {
quiz = s.getQuizFromID(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) return nil, fmt.Errorf("Quiz ID %v doesn't exist in the store!", id)
} }
} else { } else {