mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: add system setting cache (#1609)
This commit is contained in:
@ -13,6 +13,7 @@ type Store struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
profile *profile.Profile
|
profile *profile.Profile
|
||||||
|
|
||||||
|
systemSettingCache sync.Map // map[string]*systemSettingRaw
|
||||||
userCache sync.Map // map[int]*userRaw
|
userCache sync.Map // map[int]*userRaw
|
||||||
userSettingCache sync.Map // map[string]*userSettingRaw
|
userSettingCache sync.Map // map[string]*userSettingRaw
|
||||||
memoCache sync.Map // map[int]*memoRaw
|
memoCache sync.Map // map[int]*memoRaw
|
||||||
|
@ -41,7 +41,7 @@ func (s *Store) UpsertSystemSetting(ctx context.Context, upsert *api.SystemSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
systemSetting := systemSettingRaw.toSystemSetting()
|
systemSetting := systemSettingRaw.toSystemSetting()
|
||||||
|
s.systemSettingCache.Store(systemSettingRaw.Name, systemSettingRaw)
|
||||||
return systemSetting, nil
|
return systemSetting, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,13 +63,17 @@ func (s *Store) FindSystemSettingList(ctx context.Context, find *api.SystemSetti
|
|||||||
|
|
||||||
list := []*api.SystemSetting{}
|
list := []*api.SystemSetting{}
|
||||||
for _, raw := range systemSettingRawList {
|
for _, raw := range systemSettingRawList {
|
||||||
|
s.systemSettingCache.Store(raw.Name, raw)
|
||||||
list = append(list, raw.toSystemSetting())
|
list = append(list, raw.toSystemSetting())
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) FindSystemSetting(ctx context.Context, find *api.SystemSettingFind) (*api.SystemSetting, error) {
|
func (s *Store) FindSystemSetting(ctx context.Context, find *api.SystemSettingFind) (*api.SystemSetting, error) {
|
||||||
|
if systemSetting, ok := s.systemSettingCache.Load(find.Name); ok {
|
||||||
|
systemSettingRaw := systemSetting.(*systemSettingRaw)
|
||||||
|
return systemSettingRaw.toSystemSetting(), nil
|
||||||
|
}
|
||||||
tx, err := s.db.BeginTx(ctx, nil)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, FormatError(err)
|
return nil, FormatError(err)
|
||||||
@ -85,7 +89,9 @@ func (s *Store) FindSystemSetting(ctx context.Context, find *api.SystemSettingFi
|
|||||||
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("not found")}
|
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("not found")}
|
||||||
}
|
}
|
||||||
|
|
||||||
return systemSettingRawList[0].toSystemSetting(), nil
|
systemSettingRaw := systemSettingRawList[0]
|
||||||
|
s.systemSettingCache.Store(systemSettingRaw.Name, systemSettingRaw)
|
||||||
|
return systemSettingRaw.toSystemSetting(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upsertSystemSetting(ctx context.Context, tx *sql.Tx, upsert *api.SystemSettingUpsert) (*systemSettingRaw, error) {
|
func upsertSystemSetting(ctx context.Context, tx *sql.Tx, upsert *api.SystemSettingUpsert) (*systemSettingRaw, error) {
|
||||||
|
Reference in New Issue
Block a user