memos/store/store.go

47 lines
1.1 KiB
Go
Raw Normal View History

2022-05-16 07:37:23 +08:00
package store
2022-05-22 00:59:22 +08:00
import (
2022-11-06 12:21:58 +08:00
"context"
"sync"
2022-06-27 22:09:06 +08:00
2023-09-17 22:55:13 +08:00
"github.com/usememos/memos/server/profile"
2022-05-22 00:59:22 +08:00
)
2022-08-24 21:53:12 +08:00
// Store provides database access to all raw objects.
2022-05-16 07:37:23 +08:00
type Store struct {
Profile *profile.Profile
driver Driver
workspaceSettingCache sync.Map // map[string]*WorkspaceSetting
workspaceSettingV1Cache sync.Map // map[string]*storepb.WorkspaceSetting
userCache sync.Map // map[int]*User
userSettingCache sync.Map // map[string]*UserSetting
idpCache sync.Map // map[int]*IdentityProvider
2022-05-16 07:37:23 +08:00
}
2022-08-24 21:53:12 +08:00
// New creates a new instance of Store.
func New(driver Driver, profile *profile.Profile) *Store {
2022-05-16 07:37:23 +08:00
return &Store{
driver: driver,
Profile: profile,
2022-05-16 07:37:23 +08:00
}
}
2022-11-06 12:21:58 +08:00
2024-02-21 23:43:18 +08:00
func (s *Store) MigrateManually(ctx context.Context) error {
if err := s.MigrateWorkspaceSetting(ctx); err != nil {
return err
}
return nil
}
2022-11-06 12:21:58 +08:00
func (s *Store) Vacuum(ctx context.Context) error {
return s.driver.Vacuum(ctx)
2022-11-06 12:21:58 +08:00
}
func (s *Store) Close() error {
return s.driver.Close()
2022-11-06 12:21:58 +08:00
}
func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
return s.driver.GetCurrentDBSize(ctx)
}