feat(feeds): expose retained operation history and read-only rechecks
Build and publish container images / images (push) Successful in 11m14s

This commit is contained in:
Anya Tokugawa committed 2026-11-08 06:35:53 +09:00
1 parent e4c184d71c
commit 1057be6d2b
12 files changed
+547 -10

No files matched your search

+11
View File
@@ -263,6 +263,17 @@ func (s *Store) SaveFeedSource(ctx context.Context, domain, owner string, v Feed
if !errors.Is(lookup, sql.ErrNoRows) {
return lookup
}
// Do not rebind retained receipts to a different remote identity.
// Both predicates use existing indexes: owner history and the global
// partial index of unresolved operations. Other owners' terminal
// receipts remain isolated by domain/owner in metadata lookups.
var retired bool
if e := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM feed_actions WHERE domain_uuid=? AND owner_uuid=? AND source_uuid=?) OR EXISTS(SELECT 1 FROM feed_actions WHERE source_uuid=? AND status IN ('queued','preparing','sending','unknown','check_queued','checking'))`, domain, owner, v.UUID, v.UUID).Scan(&retired); e != nil {
return e
}
if retired {
return ErrTaskConflict
}
var n int
if e := tx.QueryRowContext(ctx, `SELECT count(*) FROM feed_sources WHERE domain_uuid=? AND owner_uuid=?`, domain, owner).Scan(&n); e != nil {
return e
+1 -1
View File
@@ -92,7 +92,7 @@ func (s *Store) QueueFeedAction(ctx context.Context, domain, owner string, a Fee
// Recheck is deliberately read-only at the remote side, even with writeback OFF.
func (s *Store) RecheckFeedAction(ctx context.Context, domain, owner, request string) error {
return s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
r, e := tx.ExecContext(ctx, `UPDATE feed_actions SET status='check_queued',error='' WHERE domain_uuid=? AND owner_uuid=? AND request_id=? AND status='unknown' AND until_ms<? AND EXISTS(SELECT 1 FROM feed_sources s WHERE s.uuid=feed_actions.source_uuid AND s.enabled=1)`, domain, owner, request, time.Now().UnixMilli())
r, e := tx.ExecContext(ctx, `UPDATE feed_actions SET status='check_queued',error='' WHERE domain_uuid=? AND owner_uuid=? AND request_id=? AND status='unknown' AND until_ms<? AND EXISTS(SELECT 1 FROM feed_sources s WHERE s.uuid=feed_actions.source_uuid AND s.domain_uuid=feed_actions.domain_uuid AND s.owner_uuid=feed_actions.owner_uuid AND s.provider='freshrss' AND s.enabled=1)`, domain, owner, request, time.Now().UnixMilli())
return feedActionAffected(r, e)
})
}
+109
View File
@@ -0,0 +1,109 @@
package store
import (
"context"
"strings"
"time"
"github.com/google/uuid"
)
// FeedActionRecord is a receipt plus currently available local metadata. A
// deleted source or evicted article must not hide an unresolved remote write.
type FeedActionRecord struct {
FeedAction
SourceTitle string `json:"source_title"`
ItemTitle string `json:"item_title"`
SourcePresent bool `json:"source_present"`
ItemPresent bool `json:"item_present"`
CanCheck bool `json:"can_check"`
CheckAfterMS int64 `json:"check_after_ms"`
}
type FeedActionQuery struct {
Source string
Status string
Before int64
Key string
}
const feedActionMetadata = `,COALESCE(s.title,''),COALESCE(i.title,''),s.uuid IS NOT NULL,i.id IS NOT NULL,COALESCE(s.enabled=1 AND s.provider='freshrss',0)`
const feedActionJoins = ` FROM feed_actions a LEFT JOIN feed_sources s ON s.uuid=a.source_uuid AND s.domain_uuid=a.domain_uuid AND s.owner_uuid=a.owner_uuid LEFT JOIN feed_items i ON i.source_uuid=s.uuid AND i.id=a.item_id WHERE a.domain_uuid=? AND a.owner_uuid=?`
func feedActionRecordColumns() string {
return "a." + strings.ReplaceAll(feedActionColumns, ",", ",a.") + feedActionMetadata
}
func scanFeedActionRecord(row interface{ Scan(...any) error }, writable bool) (a FeedActionRecord, e error) {
var enabled bool
e = row.Scan(&a.Domain, &a.Owner, &a.RequestID, &a.Source, &a.ID, &a.Field, &a.Desired, &a.SourceVersion, &a.Status, &a.Claim, &a.UntilMS, &a.CreatedMS, &a.Error, &a.SourceTitle, &a.ItemTitle, &a.SourcePresent, &a.ItemPresent, &enabled)
if a.Status == "unknown" {
a.CheckAfterMS = a.UntilMS
a.CanCheck = writable && enabled && a.UntilMS < time.Now().UnixMilli()
}
return
}
// FeedActionHistory returns at most 51 local receipts (50 plus a next-page
// sentinel). The owner cap of 10,000 receipts bounds the sorting work even
// without a new schema/index. No fetch, retry, expiry or deletion runs here.
func (s *Store) FeedActionHistory(ctx context.Context, domain, owner string, q FeedActionQuery) ([]FeedActionRecord, error) {
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
return nil, e
}
where := ""
switch q.Status {
case "", "unresolved":
where = ` AND a.status NOT IN ('confirmed','cancelled')`
case "all":
case "pending":
where = ` AND a.status IN ('queued','preparing','sending','check_queued','checking')`
case "unknown", "confirmed", "failed", "conflict", "cancelled":
where = ` AND a.status='` + q.Status + `'`
default:
return nil, ErrTaskInvalid
}
args := []any{domain, owner}
if q.Source != "" {
if _, e := uuid.Parse(q.Source); e != nil {
return nil, ErrTaskInvalid
}
where += ` AND a.source_uuid=?`
args = append(args, q.Source)
}
if q.Before >= 0 {
if _, e := uuid.Parse(q.Key); e != nil {
return nil, ErrTaskInvalid
}
where += ` AND (a.created_ms<? OR (a.created_ms=? AND a.request_id<?))`
args = append(args, q.Before, q.Before, q.Key)
} else if q.Before != -1 || q.Key != "" {
return nil, ErrTaskInvalid
}
writable := !s.ReadOnly && feedActor(ctx, s.DB, domain, owner, true) == nil
rows, e := s.DB.QueryContext(ctx, `SELECT `+feedActionRecordColumns()+feedActionJoins+where+` ORDER BY a.created_ms DESC,a.request_id DESC LIMIT 51`, args...)
if e != nil {
return nil, e
}
defer rows.Close()
out := []FeedActionRecord{}
for rows.Next() {
a, e := scanFeedActionRecord(rows, writable)
if e != nil {
return nil, e
}
out = append(out, a)
}
return out, rows.Err()
}
func (s *Store) FeedActionRecord(ctx context.Context, domain, owner, request string) (FeedActionRecord, error) {
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
return FeedActionRecord{}, e
}
if _, e := uuid.Parse(request); e != nil {
return FeedActionRecord{}, ErrTaskInvalid
}
writable := !s.ReadOnly && feedActor(ctx, s.DB, domain, owner, true) == nil
return scanFeedActionRecord(s.DB.QueryRowContext(ctx, `SELECT `+feedActionRecordColumns()+feedActionJoins+` AND a.request_id=?`, domain, owner, request), writable)
}