fix today memory after restart
release / docker-image (push) Successful in 1m8s
release / goreleaser (push) Successful in 10m14s

This commit is contained in:
2026-02-13 09:58:37 +03:00
parent 738dfda7a0
commit 2c6e71bad5
4 changed files with 83 additions and 3 deletions
+17
View File
@@ -2,6 +2,8 @@ package storage
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
@@ -65,6 +67,21 @@ func (s *Storage) GetShowCounts(ctx context.Context, memoNames []string) (map[st
return result, rows.Err()
}
// GetLastShownToday returns the memo_name and tier of the most recently shown memo
// within the given time range [from, to). Returns empty string if nothing was shown.
func (s *Storage) GetLastShownToday(ctx context.Context, from, to int64) (memoName string, tier int, err error) {
err = s.db.QueryRowContext(ctx,
`SELECT memo_name, tier FROM show_history WHERE shown_at >= ? AND shown_at < ? ORDER BY shown_at DESC LIMIT 1`,
from, to).Scan(&memoName, &tier)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return "", 0, nil
}
return "", 0, fmt.Errorf("get last shown today: %w", err)
}
return memoName, tier, nil
}
// RecordShow records that a memo was shown.
func (s *Storage) RecordShow(ctx context.Context, memoName string, tier int) error {
_, err := s.db.ExecContext(ctx,