feat: sync durable moderation and appeals
This commit is contained in:
parent
e1a95c7318
commit
9f467f4be7
140 changed files with 13730 additions and 316 deletions
|
|
@ -45,6 +45,46 @@ func (c *accountSettingsCache) Delete(userID int64) {
|
|||
c.cache.Invalidate(userID)
|
||||
}
|
||||
|
||||
func (c *accountSettingsCache) Store(userID int64, settings domain.AccountSettings) {
|
||||
if c == nil || userID == 0 {
|
||||
return
|
||||
}
|
||||
c.cache.Store(userID, settings)
|
||||
}
|
||||
|
||||
type accountSettingsBatchReader interface {
|
||||
GetAccountSettingsBatch(ctx context.Context, userIDs []int64) (map[int64]domain.AccountSettings, error)
|
||||
}
|
||||
|
||||
func (c *accountSettingsCache) getOrLoadBatch(
|
||||
ctx context.Context,
|
||||
userIDs []int64,
|
||||
svc accountSettingsService,
|
||||
) (map[int64]domain.AccountSettings, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return map[int64]domain.AccountSettings{}, nil
|
||||
}
|
||||
return c.cache.GetOrLoadBatch(
|
||||
ctx,
|
||||
userIDs,
|
||||
func(int64) (int64, bool) { return 0, true },
|
||||
func(ctx context.Context, missing []int64) (map[int64]domain.AccountSettings, error) {
|
||||
if batch, ok := svc.(accountSettingsBatchReader); ok {
|
||||
return batch.GetAccountSettingsBatch(ctx, missing)
|
||||
}
|
||||
out := make(map[int64]domain.AccountSettings, len(missing))
|
||||
for _, userID := range missing {
|
||||
settings, err := svc.GetAccountSettings(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out[userID] = settings
|
||||
}
|
||||
return out, nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// cachedAccountSettings 取(缓存的)账号单例设置;服务未接通返回默认。
|
||||
func (r *Router) cachedAccountSettings(ctx context.Context, userID int64) (domain.AccountSettings, error) {
|
||||
svc, ok := r.accountSettingsSvc()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue