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"
|
2023-02-11 14:19:26 +08:00
|
|
|
"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 {
|
2023-05-09 09:02:59 +08:00
|
|
|
Profile *profile.Profile
|
2023-09-26 17:16:58 +08:00
|
|
|
driver Driver
|
2023-07-02 18:56:25 +08:00
|
|
|
systemSettingCache sync.Map // map[string]*SystemSetting
|
|
|
|
userCache sync.Map // map[int]*User
|
2023-06-29 22:55:03 +08:00
|
|
|
userSettingCache sync.Map // map[string]*UserSetting
|
2023-06-26 23:46:01 +08:00
|
|
|
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.
|
2023-09-27 09:27:31 +08:00
|
|
|
func New(driver Driver, profile *profile.Profile) *Store {
|
2022-05-16 07:37:23 +08:00
|
|
|
return &Store{
|
2023-09-26 17:16:58 +08:00
|
|
|
driver: driver,
|
2024-01-02 08:29:18 +08:00
|
|
|
Profile: profile,
|
2022-05-16 07:37:23 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-06 12:21:58 +08:00
|
|
|
|
2024-01-28 07:58:53 +08:00
|
|
|
func (s *Store) MigrateManually(ctx context.Context) error {
|
|
|
|
if err := s.MigrateResourceInternalPath(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := s.MigrateResourceName(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-31 16:45:21 +08:00
|
|
|
if err := s.MigrateMemoName(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-28 07:58:53 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-11-06 12:21:58 +08:00
|
|
|
func (s *Store) Vacuum(ctx context.Context) error {
|
2023-09-27 09:27:31 +08:00
|
|
|
return s.driver.Vacuum(ctx)
|
2022-11-06 12:21:58 +08:00
|
|
|
}
|
|
|
|
|
2023-09-27 09:27:31 +08:00
|
|
|
func (s *Store) Close() error {
|
|
|
|
return s.driver.Close()
|
2022-11-06 12:21:58 +08:00
|
|
|
}
|
2023-10-16 21:07:21 +08:00
|
|
|
|
|
|
|
func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
|
|
|
|
return s.driver.GetCurrentDBSize(ctx)
|
|
|
|
}
|