fix memo selection
This commit is contained in:
@@ -103,15 +103,3 @@ func (c *Client) DownloadAttachment(ctx context.Context, att Attachment) ([]byte
|
|||||||
}
|
}
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRandomMemo fetches a single memo without any filter (for full fallback).
|
|
||||||
func (c *Client) GetRandomMemo(ctx context.Context) (*Memo, error) {
|
|
||||||
resp, err := c.ListMemos(ctx, "", 1, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(resp.Memos) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return resp.Memos[0], nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -201,17 +201,50 @@ func (s *Selector) fetchRanges(ctx context.Context, ranges []DateRange) ([]*memo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Selector) fullFallback(ctx context.Context) (*Memory, error) {
|
func (s *Selector) fullFallback(ctx context.Context) (*Memory, error) {
|
||||||
memo, err := s.client.GetRandomMemo(ctx)
|
resp, err := s.client.ListMemos(ctx, "", s.cfg.PageSize, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("full fallback: %w", err)
|
return nil, fmt.Errorf("full fallback: %w", err)
|
||||||
}
|
}
|
||||||
if memo == nil {
|
|
||||||
|
allMemos := resp.GetMemos()
|
||||||
|
if len(allMemos) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to apply relaxed cooldown
|
||||||
|
cooldownSet, err := s.store.GetCooldownMemoNames(ctx, s.cfg.RelaxedCooldownDays)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("full fallback cooldown: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var filtered []*memos.Memo
|
||||||
|
for _, m := range allMemos {
|
||||||
|
if _, blocked := cooldownSet[m.Name]; !blocked {
|
||||||
|
filtered = append(filtered, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing survives cooldown, use all memos
|
||||||
|
if len(filtered) == 0 {
|
||||||
|
filtered = allMemos
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates := make([]candidate, len(filtered))
|
||||||
|
for i, m := range filtered {
|
||||||
|
candidates[i] = candidate{memo: m}
|
||||||
|
}
|
||||||
|
|
||||||
|
picked := weightedSelect(candidates, false, 0)
|
||||||
|
if picked == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Info("selected memory via full fallback", "memo", picked.memo.Name)
|
||||||
|
|
||||||
return &Memory{
|
return &Memory{
|
||||||
Memo: memo,
|
Memo: picked.memo,
|
||||||
Tier: 0,
|
Tier: 0,
|
||||||
Date: memo.DisplayTime,
|
Date: picked.memo.DisplayTime,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user