mirror of
https://github.com/usememos/memos.git
synced 2024-09-11 12:05:29 +03:00
chore: tweak store methods name
This commit is contained in:
parent
00d25b12c1
commit
14d4cfd5a4
@ -103,7 +103,7 @@ func findObjectStorage(ctx context.Context, dataStore *store.Store) (*s3.Client,
|
||||
if workspaceStorageSetting.StorageType != storepb.WorkspaceStorageSetting_STORAGE_TYPE_EXTERNAL || workspaceStorageSetting.ActivedExternalStorageId == nil {
|
||||
return nil, nil
|
||||
}
|
||||
storage, err := dataStore.GetStorageV1(ctx, &store.FindStorage{ID: workspaceStorageSetting.ActivedExternalStorageId})
|
||||
storage, err := dataStore.GetStorage(ctx, &store.FindStorage{ID: workspaceStorageSetting.ActivedExternalStorageId})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to find storage")
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (s *APIV2Service) SignIn(ctx context.Context, request *apiv2pb.SignInReques
|
||||
}
|
||||
|
||||
func (s *APIV2Service) SignInWithSSO(ctx context.Context, request *apiv2pb.SignInWithSSORequest) (*apiv2pb.SignInWithSSOResponse, error) {
|
||||
identityProvider, err := s.Store.GetIdentityProviderV1(ctx, &store.FindIdentityProvider{
|
||||
identityProvider, err := s.Store.GetIdentityProvider(ctx, &store.FindIdentityProvider{
|
||||
ID: &request.IdpId,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -21,7 +21,7 @@ func (s *APIV2Service) CreateIdentityProvider(ctx context.Context, request *apiv
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
identityProvider, err := s.Store.CreateIdentityProviderV1(ctx, convertIdentityProviderToStore(request.IdentityProvider))
|
||||
identityProvider, err := s.Store.CreateIdentityProvider(ctx, convertIdentityProviderToStore(request.IdentityProvider))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to create identity provider, error: %+v", err)
|
||||
}
|
||||
@ -31,7 +31,7 @@ func (s *APIV2Service) CreateIdentityProvider(ctx context.Context, request *apiv
|
||||
}
|
||||
|
||||
func (s *APIV2Service) ListIdentityProviders(ctx context.Context, _ *apiv2pb.ListIdentityProvidersRequest) (*apiv2pb.ListIdentityProvidersResponse, error) {
|
||||
identityProviders, err := s.Store.ListIdentityProvidersV1(ctx, &store.FindIdentityProvider{})
|
||||
identityProviders, err := s.Store.ListIdentityProviders(ctx, &store.FindIdentityProvider{})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list identity providers, error: %+v", err)
|
||||
}
|
||||
@ -50,7 +50,7 @@ func (s *APIV2Service) GetIdentityProvider(ctx context.Context, request *apiv2pb
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid identity provider name: %v", err)
|
||||
}
|
||||
identityProvider, err := s.Store.GetIdentityProviderV1(ctx, &store.FindIdentityProvider{
|
||||
identityProvider, err := s.Store.GetIdentityProvider(ctx, &store.FindIdentityProvider{
|
||||
ID: &id,
|
||||
})
|
||||
if err != nil {
|
||||
@ -86,7 +86,7 @@ func (s *APIV2Service) UpdateIdentityProvider(ctx context.Context, request *apiv
|
||||
}
|
||||
}
|
||||
|
||||
identityProvider, err := s.Store.UpdateIdentityProviderV1(ctx, update)
|
||||
identityProvider, err := s.Store.UpdateIdentityProvider(ctx, update)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update identity provider, error: %+v", err)
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resourc
|
||||
if workspaceStorageSetting.ActivedExternalStorageId == nil {
|
||||
return errors.Errorf("No actived external storage found")
|
||||
}
|
||||
storage, err := s.GetStorageV1(ctx, &store.FindStorage{ID: workspaceStorageSetting.ActivedExternalStorageId})
|
||||
storage, err := s.GetStorage(ctx, &store.FindStorage{ID: workspaceStorageSetting.ActivedExternalStorageId})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to find actived external storage")
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func (s *APIV2Service) CreateStorage(ctx context.Context, request *apiv2pb.Creat
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
storage, err := s.Store.CreateStorageV1(ctx, convertStorageToStore(request.Storage))
|
||||
storage, err := s.Store.CreateStorage(ctx, convertStorageToStore(request.Storage))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to create storage, error: %+v", err)
|
||||
}
|
||||
@ -30,7 +30,7 @@ func (s *APIV2Service) CreateStorage(ctx context.Context, request *apiv2pb.Creat
|
||||
}
|
||||
|
||||
func (s *APIV2Service) ListStorages(ctx context.Context, _ *apiv2pb.ListStoragesRequest) (*apiv2pb.ListStoragesResponse, error) {
|
||||
storages, err := s.Store.ListStoragesV1(ctx, &store.FindStorage{})
|
||||
storages, err := s.Store.ListStorages(ctx, &store.FindStorage{})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list storages, error: %+v", err)
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (s *APIV2Service) ListStorages(ctx context.Context, _ *apiv2pb.ListStorages
|
||||
}
|
||||
|
||||
func (s *APIV2Service) GetStorage(ctx context.Context, request *apiv2pb.GetStorageRequest) (*apiv2pb.GetStorageResponse, error) {
|
||||
storage, err := s.Store.GetStorageV1(ctx, &store.FindStorage{
|
||||
storage, err := s.Store.GetStorage(ctx, &store.FindStorage{
|
||||
ID: &request.Id,
|
||||
})
|
||||
if err != nil {
|
||||
@ -77,7 +77,7 @@ func (s *APIV2Service) UpdateStorage(ctx context.Context, request *apiv2pb.Updat
|
||||
}
|
||||
}
|
||||
|
||||
storage, err := s.Store.UpdateStorageV1(ctx, update)
|
||||
storage, err := s.Store.UpdateStorage(ctx, update)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update storage, error: %+v", err)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *APIV2Service) ListWorkspaceSettings(ctx context.Context, _ *apiv2pb.ListWorkspaceSettingsRequest) (*apiv2pb.ListWorkspaceSettingsResponse, error) {
|
||||
workspaceSettings, err := s.Store.ListWorkspaceSettingsV1(ctx, &store.FindWorkspaceSetting{})
|
||||
workspaceSettings, err := s.Store.ListWorkspaceSettings(ctx, &store.FindWorkspaceSetting{})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace setting: %v", err)
|
||||
}
|
||||
@ -36,7 +36,7 @@ func (s *APIV2Service) GetWorkspaceSetting(ctx context.Context, request *apiv2pb
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid workspace setting name: %v", err)
|
||||
}
|
||||
settingKey := storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString])
|
||||
workspaceSetting, err := s.Store.GetWorkspaceSettingV1(ctx, &store.FindWorkspaceSetting{
|
||||
workspaceSetting, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
|
||||
Name: settingKey.String(),
|
||||
})
|
||||
if err != nil {
|
||||
@ -64,7 +64,7 @@ func (s *APIV2Service) SetWorkspaceSetting(ctx context.Context, request *apiv2pb
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
if _, err := s.Store.UpsertWorkspaceSettingV1(ctx, convertWorkspaceSettingToStore(request.Setting)); err != nil {
|
||||
if _, err := s.Store.UpsertWorkspaceSetting(ctx, convertWorkspaceSettingToStore(request.Setting)); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to upsert workspace setting: %v", err)
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ func (s *Server) getOrUpsertWorkspaceBasicSetting(ctx context.Context) (*storepb
|
||||
modified = true
|
||||
}
|
||||
if modified {
|
||||
workspaceSetting, err := s.Store.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
|
||||
workspaceSetting, err := s.Store.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_BASIC,
|
||||
Value: &storepb.WorkspaceSetting_BasicSetting{BasicSetting: workspaceBasicSetting},
|
||||
})
|
||||
|
@ -4,6 +4,6 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func getUserSettingV1CacheKey(userID int32, key string) string {
|
||||
func getUserSettingCacheKey(userID int32, key string) string {
|
||||
return fmt.Sprintf("%d-%s-v1", userID, key)
|
||||
}
|
||||
|
18
store/idp.go
18
store/idp.go
@ -32,7 +32,7 @@ type DeleteIdentityProvider struct {
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateIdentityProviderV1(ctx context.Context, create *storepb.IdentityProvider) (*storepb.IdentityProvider, error) {
|
||||
func (s *Store) CreateIdentityProvider(ctx context.Context, create *storepb.IdentityProvider) (*storepb.IdentityProvider, error) {
|
||||
raw, err := convertIdentityProviderToRaw(create)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -46,11 +46,11 @@ func (s *Store) CreateIdentityProviderV1(ctx context.Context, create *storepb.Id
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.idpV1Cache.Store(identityProvider.Id, identityProvider)
|
||||
s.idpCache.Store(identityProvider.Id, identityProvider)
|
||||
return identityProvider, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListIdentityProvidersV1(ctx context.Context, find *FindIdentityProvider) ([]*storepb.IdentityProvider, error) {
|
||||
func (s *Store) ListIdentityProviders(ctx context.Context, find *FindIdentityProvider) ([]*storepb.IdentityProvider, error) {
|
||||
list, err := s.driver.ListIdentityProviders(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -62,19 +62,19 @@ func (s *Store) ListIdentityProvidersV1(ctx context.Context, find *FindIdentityP
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.idpV1Cache.Store(identityProvider.Id, identityProvider)
|
||||
s.idpCache.Store(identityProvider.Id, identityProvider)
|
||||
}
|
||||
return identityProviders, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetIdentityProviderV1(ctx context.Context, find *FindIdentityProvider) (*storepb.IdentityProvider, error) {
|
||||
func (s *Store) GetIdentityProvider(ctx context.Context, find *FindIdentityProvider) (*storepb.IdentityProvider, error) {
|
||||
if find.ID != nil {
|
||||
if cache, ok := s.idpV1Cache.Load(*find.ID); ok {
|
||||
if cache, ok := s.idpCache.Load(*find.ID); ok {
|
||||
return cache.(*storepb.IdentityProvider), nil
|
||||
}
|
||||
}
|
||||
|
||||
list, err := s.ListIdentityProvidersV1(ctx, find)
|
||||
list, err := s.ListIdentityProviders(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -97,7 +97,7 @@ type UpdateIdentityProviderV1 struct {
|
||||
Config *storepb.IdentityProviderConfig
|
||||
}
|
||||
|
||||
func (s *Store) UpdateIdentityProviderV1(ctx context.Context, update *UpdateIdentityProviderV1) (*storepb.IdentityProvider, error) {
|
||||
func (s *Store) UpdateIdentityProvider(ctx context.Context, update *UpdateIdentityProviderV1) (*storepb.IdentityProvider, error) {
|
||||
updateRaw := &UpdateIdentityProvider{
|
||||
ID: update.ID,
|
||||
}
|
||||
@ -123,7 +123,7 @@ func (s *Store) UpdateIdentityProviderV1(ctx context.Context, update *UpdateIden
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.idpV1Cache.Store(identityProvider.Id, identityProvider)
|
||||
s.idpCache.Store(identityProvider.Id, identityProvider)
|
||||
return identityProvider, nil
|
||||
}
|
||||
|
||||
|
@ -1,77 +1 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
storepb "github.com/usememos/memos/proto/gen/store"
|
||||
)
|
||||
|
||||
// MigrateWorkspaceSetting migrates workspace setting from v1 to v2.
|
||||
func (s *Store) MigrateWorkspaceSetting(ctx context.Context) error {
|
||||
workspaceSettings, err := s.ListWorkspaceSettings(ctx, &FindWorkspaceSetting{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list workspace settings")
|
||||
}
|
||||
|
||||
workspaceBasicSetting, err := s.GetWorkspaceBasicSetting(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get workspace basic setting")
|
||||
}
|
||||
|
||||
workspaceGeneralSetting, err := s.GetWorkspaceGeneralSetting(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get workspace general setting")
|
||||
}
|
||||
|
||||
for _, workspaceSetting := range workspaceSettings {
|
||||
matched := true
|
||||
var baseValue any
|
||||
// nolint
|
||||
json.Unmarshal([]byte(workspaceSetting.Value), &baseValue)
|
||||
if workspaceSetting.Name == "server-id" {
|
||||
workspaceBasicSetting.ServerId = workspaceSetting.Value
|
||||
} else if workspaceSetting.Name == "secret-session" {
|
||||
workspaceBasicSetting.SecretKey = workspaceSetting.Value
|
||||
} else if workspaceSetting.Name == "allow-signup" {
|
||||
workspaceGeneralSetting.DisallowSignup = !baseValue.(bool)
|
||||
} else if workspaceSetting.Name == "disable-password-login" {
|
||||
workspaceGeneralSetting.DisallowPasswordLogin = baseValue.(bool)
|
||||
} else if workspaceSetting.Name == "additional-style" {
|
||||
workspaceGeneralSetting.AdditionalStyle = baseValue.(string)
|
||||
} else if workspaceSetting.Name == "additional-script" {
|
||||
workspaceGeneralSetting.AdditionalScript = baseValue.(string)
|
||||
} else if workspaceSetting.Name == "instance-url" {
|
||||
workspaceGeneralSetting.InstanceUrl = workspaceSetting.Value
|
||||
} else {
|
||||
matched = false
|
||||
}
|
||||
|
||||
if matched {
|
||||
if err := s.DeleteWorkspaceSetting(ctx, &DeleteWorkspaceSetting{
|
||||
Name: workspaceSetting.Name,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to delete workspace setting: %s", workspaceSetting.Name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := s.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_BASIC,
|
||||
Value: &storepb.WorkspaceSetting_BasicSetting{BasicSetting: workspaceBasicSetting},
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "failed to upsert workspace basic setting")
|
||||
}
|
||||
|
||||
if _, err := s.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_GeneralSetting{GeneralSetting: workspaceGeneralSetting},
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "failed to upsert workspace general setting")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -30,35 +30,7 @@ type DeleteStorage struct {
|
||||
ID int32
|
||||
}
|
||||
|
||||
func (s *Store) CreateStorage(ctx context.Context, create *Storage) (*Storage, error) {
|
||||
return s.driver.CreateStorage(ctx, create)
|
||||
}
|
||||
|
||||
func (s *Store) ListStorages(ctx context.Context, find *FindStorage) ([]*Storage, error) {
|
||||
return s.driver.ListStorages(ctx, find)
|
||||
}
|
||||
|
||||
func (s *Store) GetStorage(ctx context.Context, find *FindStorage) (*Storage, error) {
|
||||
list, err := s.ListStorages(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(list) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return list[0], nil
|
||||
}
|
||||
|
||||
func (s *Store) UpdateStorage(ctx context.Context, update *UpdateStorage) (*Storage, error) {
|
||||
return s.driver.UpdateStorage(ctx, update)
|
||||
}
|
||||
|
||||
func (s *Store) DeleteStorage(ctx context.Context, delete *DeleteStorage) error {
|
||||
return s.driver.DeleteStorage(ctx, delete)
|
||||
}
|
||||
|
||||
func (s *Store) CreateStorageV1(ctx context.Context, create *storepb.Storage) (*storepb.Storage, error) {
|
||||
func (s *Store) CreateStorage(ctx context.Context, create *storepb.Storage) (*storepb.Storage, error) {
|
||||
storageRaw := &Storage{
|
||||
Name: create.Name,
|
||||
Type: create.Type.String(),
|
||||
@ -83,7 +55,7 @@ func (s *Store) CreateStorageV1(ctx context.Context, create *storepb.Storage) (*
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListStoragesV1(ctx context.Context, find *FindStorage) ([]*storepb.Storage, error) {
|
||||
func (s *Store) ListStorages(ctx context.Context, find *FindStorage) ([]*storepb.Storage, error) {
|
||||
list, err := s.driver.ListStorages(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -100,8 +72,8 @@ func (s *Store) ListStoragesV1(ctx context.Context, find *FindStorage) ([]*store
|
||||
return storages, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetStorageV1(ctx context.Context, find *FindStorage) (*storepb.Storage, error) {
|
||||
list, err := s.ListStoragesV1(ctx, find)
|
||||
func (s *Store) GetStorage(ctx context.Context, find *FindStorage) (*storepb.Storage, error) {
|
||||
list, err := s.ListStorages(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -119,7 +91,7 @@ type UpdateStorageV1 struct {
|
||||
Config *storepb.StorageConfig
|
||||
}
|
||||
|
||||
func (s *Store) UpdateStorageV1(ctx context.Context, update *UpdateStorageV1) (*storepb.Storage, error) {
|
||||
func (s *Store) UpdateStorage(ctx context.Context, update *UpdateStorageV1) (*storepb.Storage, error) {
|
||||
updateRaw := &UpdateStorage{
|
||||
ID: update.ID,
|
||||
}
|
||||
@ -144,6 +116,10 @@ func (s *Store) UpdateStorageV1(ctx context.Context, update *UpdateStorageV1) (*
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
func (s *Store) DeleteStorage(ctx context.Context, delete *DeleteStorage) error {
|
||||
return s.driver.DeleteStorage(ctx, delete)
|
||||
}
|
||||
|
||||
func convertStorageFromRaw(storageRaw *Storage) (*storepb.Storage, error) {
|
||||
storage := &storepb.Storage{
|
||||
Id: storageRaw.ID,
|
||||
|
@ -14,8 +14,7 @@ type Store struct {
|
||||
workspaceSettingCache sync.Map // map[string]*storepb.WorkspaceSetting
|
||||
userCache sync.Map // map[int]*User
|
||||
userSettingCache sync.Map // map[string]*UserSetting
|
||||
idpCache sync.Map // map[int]*IdentityProvider
|
||||
idpV1Cache sync.Map // map[int]*storepb.IdentityProvider
|
||||
idpCache sync.Map // map[int]*storepb.IdentityProvider
|
||||
}
|
||||
|
||||
// New creates a new instance of Store.
|
||||
@ -27,9 +26,6 @@ func New(driver Driver, profile *profile.Profile) *Store {
|
||||
}
|
||||
|
||||
func (s *Store) MigrateManually(ctx context.Context) error {
|
||||
if err := s.MigrateWorkspaceSetting(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ func (s *Store) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetti
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.userSettingCache.Store(getUserSettingV1CacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
s.userSettingCache.Store(getUserSettingCacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
return userSetting, nil
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func (s *Store) ListUserSettings(ctx context.Context, find *FindUserSetting) ([]
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.userSettingCache.Store(getUserSettingV1CacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
s.userSettingCache.Store(getUserSettingCacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
userSettings = append(userSettings, userSetting)
|
||||
}
|
||||
return userSettings, nil
|
||||
@ -58,7 +58,7 @@ 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(getUserSettingV1CacheKey(*find.UserID, find.Key.String())); ok {
|
||||
if cache, ok := s.userSettingCache.Load(getUserSettingCacheKey(*find.UserID, find.Key.String())); ok {
|
||||
return cache.(*storepb.UserSetting), nil
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*sto
|
||||
}
|
||||
|
||||
userSetting := list[0]
|
||||
s.userSettingCache.Store(getUserSettingV1CacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
s.userSettingCache.Store(getUserSettingCacheKey(userSetting.UserId, userSetting.Key.String()), userSetting)
|
||||
return userSetting, nil
|
||||
}
|
||||
|
||||
|
@ -23,41 +23,7 @@ type DeleteWorkspaceSetting struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (s *Store) UpsertWorkspaceSetting(ctx context.Context, upsert *WorkspaceSetting) (*WorkspaceSetting, error) {
|
||||
return s.driver.UpsertWorkspaceSetting(ctx, upsert)
|
||||
}
|
||||
|
||||
func (s *Store) ListWorkspaceSettings(ctx context.Context, find *FindWorkspaceSetting) ([]*WorkspaceSetting, error) {
|
||||
list, err := s.driver.ListWorkspaceSettings(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceSetting(ctx context.Context, find *FindWorkspaceSetting) (*WorkspaceSetting, error) {
|
||||
list, err := s.ListWorkspaceSettings(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(list) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
systemSettingMessage := list[0]
|
||||
return systemSettingMessage, nil
|
||||
}
|
||||
|
||||
func (s *Store) DeleteWorkspaceSetting(ctx context.Context, delete *DeleteWorkspaceSetting) error {
|
||||
err := s.driver.DeleteWorkspaceSetting(ctx, delete)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to delete workspace setting")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
func (s *Store) UpsertWorkspaceSetting(ctx context.Context, upsert *storepb.WorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
workspaceSettingRaw := &WorkspaceSetting{
|
||||
Name: upsert.Key.String(),
|
||||
}
|
||||
@ -91,7 +57,7 @@ func (s *Store) UpsertWorkspaceSettingV1(ctx context.Context, upsert *storepb.Wo
|
||||
return workspaceSetting, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListWorkspaceSettingsV1(ctx context.Context, find *FindWorkspaceSetting) ([]*storepb.WorkspaceSetting, error) {
|
||||
func (s *Store) ListWorkspaceSettings(ctx context.Context, find *FindWorkspaceSetting) ([]*storepb.WorkspaceSetting, error) {
|
||||
list, err := s.driver.ListWorkspaceSettings(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -109,12 +75,12 @@ func (s *Store) ListWorkspaceSettingsV1(ctx context.Context, find *FindWorkspace
|
||||
return workspaceSettings, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceSettingV1(ctx context.Context, find *FindWorkspaceSetting) (*storepb.WorkspaceSetting, error) {
|
||||
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
|
||||
}
|
||||
|
||||
list, err := s.ListWorkspaceSettingsV1(ctx, find)
|
||||
list, err := s.ListWorkspaceSettings(ctx, find)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -128,7 +94,7 @@ func (s *Store) GetWorkspaceSettingV1(ctx context.Context, find *FindWorkspaceSe
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceBasicSetting(ctx context.Context) (*storepb.WorkspaceBasicSetting, error) {
|
||||
workspaceSetting, err := s.GetWorkspaceSettingV1(ctx, &FindWorkspaceSetting{
|
||||
workspaceSetting, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
|
||||
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_BASIC.String(),
|
||||
})
|
||||
if err != nil {
|
||||
@ -143,7 +109,7 @@ func (s *Store) GetWorkspaceBasicSetting(ctx context.Context) (*storepb.Workspac
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.WorkspaceGeneralSetting, error) {
|
||||
workspaceSetting, err := s.GetWorkspaceSettingV1(ctx, &FindWorkspaceSetting{
|
||||
workspaceSetting, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
|
||||
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL.String(),
|
||||
})
|
||||
if err != nil {
|
||||
@ -158,7 +124,7 @@ func (s *Store) GetWorkspaceGeneralSetting(ctx context.Context) (*storepb.Worksp
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceMemoRelatedSetting(ctx context.Context) (*storepb.WorkspaceMemoRelatedSetting, error) {
|
||||
workspaceSetting, err := s.GetWorkspaceSettingV1(ctx, &FindWorkspaceSetting{
|
||||
workspaceSetting, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
|
||||
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_MEMO_RELATED.String(),
|
||||
})
|
||||
if err != nil {
|
||||
@ -179,7 +145,7 @@ const (
|
||||
)
|
||||
|
||||
func (s *Store) GetWorkspaceStorageSetting(ctx context.Context) (*storepb.WorkspaceStorageSetting, error) {
|
||||
workspaceSetting, err := s.GetWorkspaceSettingV1(ctx, &FindWorkspaceSetting{
|
||||
workspaceSetting, err := s.GetWorkspaceSetting(ctx, &FindWorkspaceSetting{
|
||||
Name: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_STORAGE.String(),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
func TestIdentityProviderStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ts := NewTestingStore(ctx, t)
|
||||
createdIDP, err := ts.CreateIdentityProviderV1(ctx, &storepb.IdentityProvider{
|
||||
createdIDP, err := ts.CreateIdentityProvider(ctx, &storepb.IdentityProvider{
|
||||
Name: "GitHub OAuth",
|
||||
Type: storepb.IdentityProvider_OAUTH2,
|
||||
IdentifierFilter: "",
|
||||
@ -36,14 +36,14 @@ func TestIdentityProviderStore(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
idp, err := ts.GetIdentityProviderV1(ctx, &store.FindIdentityProvider{
|
||||
idp, err := ts.GetIdentityProvider(ctx, &store.FindIdentityProvider{
|
||||
ID: &createdIDP.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, idp)
|
||||
require.Equal(t, createdIDP, idp)
|
||||
newName := "My GitHub OAuth"
|
||||
updatedIdp, err := ts.UpdateIdentityProviderV1(ctx, &store.UpdateIdentityProviderV1{
|
||||
updatedIdp, err := ts.UpdateIdentityProvider(ctx, &store.UpdateIdentityProviderV1{
|
||||
ID: idp.Id,
|
||||
Name: &newName,
|
||||
})
|
||||
@ -53,7 +53,7 @@ func TestIdentityProviderStore(t *testing.T) {
|
||||
ID: idp.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
idpList, err := ts.ListIdentityProvidersV1(ctx, &store.FindIdentityProvider{})
|
||||
idpList, err := ts.ListIdentityProviders(ctx, &store.FindIdentityProvider{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(idpList))
|
||||
ts.Close()
|
||||
|
@ -6,21 +6,29 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
storepb "github.com/usememos/memos/proto/gen/store"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
func TestStorageStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ts := NewTestingStore(ctx, t)
|
||||
storage, err := ts.CreateStorage(ctx, &store.Storage{
|
||||
Name: "test_storage",
|
||||
Type: "S3",
|
||||
Config: "{}",
|
||||
storage, err := ts.CreateStorage(ctx, &storepb.Storage{
|
||||
Name: "test_storage",
|
||||
Type: storepb.Storage_S3,
|
||||
Config: &storepb.StorageConfig{
|
||||
StorageConfig: &storepb.StorageConfig_S3Config{
|
||||
S3Config: &storepb.S3Config{
|
||||
EndPoint: "http://localhost:9000",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
newStorageName := "new_storage_name"
|
||||
updatedStorage, err := ts.UpdateStorage(ctx, &store.UpdateStorage{
|
||||
ID: storage.ID,
|
||||
updatedStorage, err := ts.UpdateStorage(ctx, &store.UpdateStorageV1{
|
||||
ID: storage.Id,
|
||||
Type: storage.Type,
|
||||
Name: &newStorageName,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@ -30,7 +38,7 @@ func TestStorageStore(t *testing.T) {
|
||||
require.Equal(t, 1, len(storageList))
|
||||
require.Equal(t, updatedStorage, storageList[0])
|
||||
err = ts.DeleteStorage(ctx, &store.DeleteStorage{
|
||||
ID: storage.ID,
|
||||
ID: storage.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
storageList, err = ts.ListStorages(ctx, &store.FindStorage{})
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
func TestWorkspaceSettingV1Store(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ts := NewTestingStore(ctx, t)
|
||||
workspaceSetting, err := ts.UpsertWorkspaceSettingV1(ctx, &storepb.WorkspaceSetting{
|
||||
workspaceSetting, err := ts.UpsertWorkspaceSetting(ctx, &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
|
||||
Value: &storepb.WorkspaceSetting_GeneralSetting{
|
||||
GeneralSetting: &storepb.WorkspaceGeneralSetting{
|
||||
@ -22,7 +22,7 @@ func TestWorkspaceSettingV1Store(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
list, err := ts.ListWorkspaceSettingsV1(ctx, &store.FindWorkspaceSetting{})
|
||||
list, err := ts.ListWorkspaceSettings(ctx, &store.FindWorkspaceSetting{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(list))
|
||||
require.Equal(t, workspaceSetting, list[0])
|
||||
|
Loading…
Reference in New Issue
Block a user