memos/store/store.go
johnnyjoygh 715306ea66 chore: enrich access tokens setting page
Settings drops the all-in-one bordered card for a de-carded layout in
the property-rail design language: a sticky table-of-contents rail at
md+ (Settings wordmark, uppercase group labels, quiet anchor rows) and
a horizontally swipeable chip strip below md, replacing the mobile
section dropdown. Nav items are real anchors with aria-current, and
switching sections scrolls back to the top.

Access Tokens becomes a first-class section with an explainer panel:
what a PAT is and a copyable curl example (real instance origin,
memos_pat_ prefix) beside token-safety guidelines in a two-column band,
with a Learn more docs link and the tokens table beneath. Successful
PAT authentication now records the token's lastUsedAt asynchronously
inside resolveBearer, with a clone-before-mutate cache guard and
monotonic writes in the store, surfaced in a Last used column.

Also localizes the create dialog's 90 Days label, lets the My Account
row wrap instead of clipping on narrow screens, and drops the dead
select-section key from all locales.
2026-07-18 10:41:53 +08:00

80 lines
1.9 KiB
Go

package store
import (
"sync"
"time"
"github.com/usememos/memos/internal/profile"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store/cache"
)
// Store provides database access to all raw objects.
type Store struct {
profile *profile.Profile
driver Driver
userCreateMu sync.Mutex
authConfigMu sync.Mutex
patMu sync.Mutex
deploymentConfigMu sync.RWMutex
deploymentConfig *deploymentConfiguration
// Cache settings
cacheConfig cache.Config
// Caches
instanceSettingCache *cache.Cache // cache for instance settings
userCache *cache.Cache // cache for users
userSettingCache *cache.Cache // cache for user settings
}
type deploymentConfiguration struct {
identityProviders map[string]*storepb.IdentityProvider
instanceSettings map[storepb.InstanceSettingKey]*storepb.InstanceSetting
}
// New creates a new instance of Store.
func New(driver Driver, profile *profile.Profile) *Store {
// Default cache settings
cacheConfig := cache.Config{
DefaultTTL: 10 * time.Minute,
CleanupInterval: 5 * time.Minute,
MaxItems: 1000,
OnEviction: nil,
}
store := &Store{
driver: driver,
profile: profile,
cacheConfig: cacheConfig,
instanceSettingCache: cache.New(cacheConfig),
userCache: cache.New(cacheConfig),
userSettingCache: cache.New(cacheConfig),
deploymentConfig: &deploymentConfiguration{
identityProviders: map[string]*storepb.IdentityProvider{},
instanceSettings: map[storepb.InstanceSettingKey]*storepb.InstanceSetting{},
},
}
return store
}
func (s *Store) GetDriver() Driver {
return s.driver
}
// GetDataDir returns the store data directory.
func (s *Store) GetDataDir() string {
return s.profile.Data
}
func (s *Store) Close() error {
// Stop all cache cleanup goroutines
s.instanceSettingCache.Close()
s.userCache.Close()
s.userSettingCache.Close()
return s.driver.Close()
}