store.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. systemSettingCache sync.Map // map[string]*SystemSetting
  12. userCache sync.Map // map[int]*User
  13. userSettingCache sync.Map // map[string]*UserSetting
  14. idpCache sync.Map // map[int]*IdentityProvider
  15. }
  16. // New creates a new instance of Store.
  17. func New(driver Driver, profile *profile.Profile) *Store {
  18. return &Store{
  19. driver: driver,
  20. Profile: profile,
  21. }
  22. }
  23. func (s *Store) MigrateManually(ctx context.Context) error {
  24. if err := s.MigrateResourceInternalPath(ctx); err != nil {
  25. return err
  26. }
  27. if err := s.MigrateResourceName(ctx); err != nil {
  28. return err
  29. }
  30. return nil
  31. }
  32. func (s *Store) Vacuum(ctx context.Context) error {
  33. return s.driver.Vacuum(ctx)
  34. }
  35. func (s *Store) Close() error {
  36. return s.driver.Close()
  37. }
  38. func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
  39. return s.driver.GetCurrentDBSize(ctx)
  40. }