store.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package store
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/usememos/memos/server/profile"
  6. )
  7. // Store provides database access to all raw objects.
  8. type Store struct {
  9. Profile *profile.Profile
  10. driver Driver
  11. workspaceSettingCache sync.Map // map[string]*WorkspaceSetting
  12. workspaceSettingV1Cache sync.Map // map[string]*storepb.WorkspaceSetting
  13. userCache sync.Map // map[int]*User
  14. userSettingCache sync.Map // map[string]*UserSetting
  15. idpCache sync.Map // map[int]*IdentityProvider
  16. }
  17. // New creates a new instance of Store.
  18. func New(driver Driver, profile *profile.Profile) *Store {
  19. return &Store{
  20. driver: driver,
  21. Profile: profile,
  22. }
  23. }
  24. func (s *Store) MigrateManually(ctx context.Context) error {
  25. if err := s.MigrateWorkspaceSetting(ctx); err != nil {
  26. return err
  27. }
  28. return nil
  29. }
  30. func (s *Store) Vacuum(ctx context.Context) error {
  31. return s.driver.Vacuum(ctx)
  32. }
  33. func (s *Store) Close() error {
  34. return s.driver.Close()
  35. }
  36. func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
  37. return s.driver.GetCurrentDBSize(ctx)
  38. }