memos/store/store.go
Lincoln Nogueira 279cba0e6b
chore: greatly speed up migrator and lower memory usage (#2874)
* chore: add en-GB language

* chore: remove en-GB contents

* chore: prevent visitors from breaking demo
- prevent disabling password login
- prevent updating `memos-demo` user
- prevent setting additional style
- prevent setting additional script
- add some error feedback to system settings UI

* Revert "chore: add en-GB language"

This reverts commit 2716377b04.

* chore: speed-up migrator and lower memory usage
- remove all Store indirections
- query database directly with prepared statements

* chore: fix golangci-lint warnings
2024-01-31 16:45:21 +08:00

51 lines
1.1 KiB
Go

package store
import (
"context"
"sync"
"github.com/usememos/memos/server/profile"
)
// Store provides database access to all raw objects.
type Store struct {
Profile *profile.Profile
driver Driver
systemSettingCache sync.Map // map[string]*SystemSetting
userCache sync.Map // map[int]*User
userSettingCache sync.Map // map[string]*UserSetting
idpCache sync.Map // map[int]*IdentityProvider
}
// New creates a new instance of Store.
func New(driver Driver, profile *profile.Profile) *Store {
return &Store{
driver: driver,
Profile: profile,
}
}
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
}
if err := s.MigrateMemoName(ctx); err != nil {
return err
}
return nil
}
func (s *Store) Vacuum(ctx context.Context) error {
return s.driver.Vacuum(ctx)
}
func (s *Store) Close() error {
return s.driver.Close()
}
func (s *Store) GetCurrentDBSize(ctx context.Context) (int64, error) {
return s.driver.GetCurrentDBSize(ctx)
}