From 9649822f2675d108352e733847fd52f5d09d5cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Thu, 19 Dec 2024 13:01:27 +0100 Subject: [PATCH] invalidate user cache when adding new user --- tools/walletextension/storage/storage_with_cache.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/walletextension/storage/storage_with_cache.go b/tools/walletextension/storage/storage_with_cache.go index 8f5fca5a0..96148c8c7 100644 --- a/tools/walletextension/storage/storage_with_cache.go +++ b/tools/walletextension/storage/storage_with_cache.go @@ -1,6 +1,8 @@ package storage import ( + "fmt" + "github.com/ethereum/go-ethereum/log" "github.com/ten-protocol/go-ten/go/common/viewingkey" "github.com/ten-protocol/go-ten/tools/walletextension/cache" @@ -29,7 +31,14 @@ func NewUserStorageWithCache(storage UserStorage, logger log.Logger) (*UserStora // AddUser adds a new user and invalidates the cache for the userID func (s *UserStorageWithCache) AddUser(userID []byte, privateKey []byte) error { - return s.storage.AddUser(userID, privateKey) + fmt.Printf("Adding user %s to CosmosDB\n", userID) + err := s.storage.AddUser(userID, privateKey) + if err != nil { + return err + } + fmt.Printf("User %s added to CosmosDB successfully\n", userID) + s.cache.Remove(userID) + return nil } // DeleteUser deletes a user and invalidates the cache for the userID