Skip to content

Commit

Permalink
Prevent database reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
aminst committed Feb 18, 2024
1 parent f884b69 commit 6e1a7b9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ func (s *StorageHandler) UnlockStorage(storageID int) {
func (s *StorageHandler) InitDatabase() error {
log.Debug().Msgf("Initializing the redis database")
for _, client := range s.storages {
err := client.FlushAll(context.Background()).Err()
// Do not reinitialize the database if it is already initialized
dbsize, err := client.DBSize(context.Background()).Result()
if err != nil {
return err
}
if dbsize == (int64((math.Pow(float64(s.shift+1), float64(s.treeHeight))))-1)*2 {
continue
}
err = client.FlushAll(context.Background()).Err()
if err != nil {
return err
}
Expand Down

0 comments on commit 6e1a7b9

Please sign in to comment.