From cf423026a5ae8ed89f4314d9ff9023f6549bc4df Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 May 2024 13:19:31 +0800 Subject: [PATCH] chore: update store cache --- store/cache.go | 2 +- store/idp.go | 5 ++++- store/store.go | 2 +- store/user.go | 6 ++++-- store/user_setting.go | 5 ++++- store/workspace_setting.go | 7 +++++-- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/store/cache.go b/store/cache.go index 05ce28c49..2a060f9bc 100644 --- a/store/cache.go +++ b/store/cache.go @@ -5,5 +5,5 @@ import ( ) func getUserSettingCacheKey(userID int32, key string) string { - return fmt.Sprintf("%d-%s-v1", userID, key) + return fmt.Sprintf("%d-%s", userID, key) } diff --git a/store/idp.go b/store/idp.go index 6aceec480..e5608e577 100644 --- a/store/idp.go +++ b/store/idp.go @@ -70,7 +70,10 @@ func (s *Store) ListIdentityProviders(ctx context.Context, find *FindIdentityPro func (s *Store) GetIdentityProvider(ctx context.Context, find *FindIdentityProvider) (*storepb.IdentityProvider, error) { if find.ID != nil { if cache, ok := s.idpCache.Load(*find.ID); ok { - return cache.(*storepb.IdentityProvider), nil + identityProvider, ok := cache.(*storepb.IdentityProvider) + if ok { + return identityProvider, nil + } } } diff --git a/store/store.go b/store/store.go index 962951cb8..c0cfac8f4 100644 --- a/store/store.go +++ b/store/store.go @@ -13,7 +13,7 @@ type Store struct { driver Driver workspaceSettingCache sync.Map // map[string]*storepb.WorkspaceSetting userCache sync.Map // map[int]*User - userSettingCache sync.Map // map[string]*UserSetting + userSettingCache sync.Map // map[string]*storepb.UserSetting idpCache sync.Map // map[int]*storepb.IdentityProvider } diff --git a/store/user.go b/store/user.go index 2457a64a4..e61d876ee 100644 --- a/store/user.go +++ b/store/user.go @@ -131,9 +131,11 @@ func (s *Store) GetUser(ctx context.Context, find *FindUser) (*User, error) { if *find.ID == SystemBotID { return SystemBot, nil } - if cache, ok := s.userCache.Load(*find.ID); ok { - return cache.(*User), nil + user, ok := cache.(*User) + if ok { + return user, nil + } } } diff --git a/store/user_setting.go b/store/user_setting.go index c82e6a9de..c50bf7b30 100644 --- a/store/user_setting.go +++ b/store/user_setting.go @@ -65,7 +65,10 @@ func (s *Store) ListUserSettings(ctx context.Context, find *FindUserSetting) ([] func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*storepb.UserSetting, error) { if find.UserID != nil { if cache, ok := s.userSettingCache.Load(getUserSettingCacheKey(*find.UserID, find.Key.String())); ok { - return cache.(*storepb.UserSetting), nil + userSetting, ok := cache.(*storepb.UserSetting) + if ok { + return userSetting, nil + } } } diff --git a/store/workspace_setting.go b/store/workspace_setting.go index c34bb3286..de33bccff 100644 --- a/store/workspace_setting.go +++ b/store/workspace_setting.go @@ -80,7 +80,10 @@ func (s *Store) ListWorkspaceSettings(ctx context.Context, find *FindWorkspaceSe func (s *Store) GetWorkspaceSetting(ctx context.Context, find *FindWorkspaceSetting) (*storepb.WorkspaceSetting, error) { if cache, ok := s.workspaceSettingCache.Load(find.Name); ok { - return cache.(*storepb.WorkspaceSetting), nil + workspaceSetting, ok := cache.(*storepb.WorkspaceSetting) + if ok { + return workspaceSetting, nil + } } list, err := s.ListWorkspaceSettings(ctx, find) @@ -91,7 +94,7 @@ func (s *Store) GetWorkspaceSetting(ctx context.Context, find *FindWorkspaceSett return nil, nil } if len(list) > 1 { - return nil, errors.Errorf("Found multiple workspace settings with key %s", find.Name) + return nil, errors.Errorf("found multiple workspace settings with key %s", find.Name) } return list[0], nil }