add load more command
This commit is contained in:
@@ -68,3 +68,33 @@ func (s *Service) GetTodayMemory(ctx context.Context) (*search.Memory, error) {
|
||||
|
||||
return mem, nil
|
||||
}
|
||||
|
||||
// LoadNewMemory selects a new memory ignoring the cache, records the show,
|
||||
// and updates the cache so that subsequent GetTodayMemory calls return it.
|
||||
func (s *Service) LoadNewMemory(ctx context.Context) (*search.Memory, error) {
|
||||
today := time.Now().In(s.loc)
|
||||
dayKey := today.Format("2006-01-02")
|
||||
|
||||
s.logger.Info("loading additional memory", "date", dayKey)
|
||||
|
||||
mem, err := s.selector.Select(ctx, today)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if mem == nil {
|
||||
s.logger.Warn("no memory found for load more")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err := s.store.RecordShow(ctx, mem.Memo.Name, mem.Tier); err != nil {
|
||||
s.logger.Error("failed to record show", "error", err)
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.cacheDay = dayKey
|
||||
s.cached = mem
|
||||
s.mu.Unlock()
|
||||
|
||||
return mem, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user