summaryrefslogtreecommitdiff
path: root/internal/storage/db.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-15 21:10:05 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-15 21:10:05 +0000
commit52f6bdee9297b48938242d3ac843cc054d7dbcaa (patch)
tree24d021106b851766e6374ee5362e8fba04898f31 /internal/storage/db.go
parent5fccaa636cd400cd7809a1d2e4f254c3fff58218 (diff)
feat: overhaul auto-refresh system with intelligent polling and differential updates
Diffstat (limited to 'internal/storage/db.go')
-rw-r--r--internal/storage/db.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go
index 69bcf68..a77b1b1 100644
--- a/internal/storage/db.go
+++ b/internal/storage/db.go
@@ -146,6 +146,10 @@ func (s *DB) ListTasks(filter TaskFilter) ([]*task.Task, error) {
query += " AND state = ?"
args = append(args, string(filter.State))
}
+ if !filter.Since.IsZero() {
+ query += " AND updated_at > ?"
+ args = append(args, filter.Since.UTC())
+ }
query += " ORDER BY created_at DESC"
if filter.Limit > 0 {
query += " LIMIT ?"
@@ -350,6 +354,33 @@ func (s *DB) UpdateTask(id string, u TaskUpdate) error {
type TaskFilter struct {
State task.State
Limit int
+ Since time.Time
+}
+
+// GetMaxUpdatedAt returns the most recent updated_at timestamp across all tasks.
+func (s *DB) GetMaxUpdatedAt() (time.Time, error) {
+ var t sql.NullString
+ err := s.db.QueryRow(`SELECT MAX(updated_at) FROM tasks`).Scan(&t)
+ if err != nil {
+ return time.Time{}, err
+ }
+ if !t.Valid || t.String == "" {
+ return time.Time{}, nil
+ }
+ // Try parsing different formats SQLite might return
+ formats := []string{
+ "2006-01-02 15:04:05.999999999-07:00",
+ "2006-01-02T15:04:05Z07:00",
+ time.RFC3339,
+ "2006-01-02 15:04:05",
+ }
+ for _, f := range formats {
+ parsed, err := time.Parse(f, t.String)
+ if err == nil {
+ return parsed.UTC(), nil
+ }
+ }
+ return time.Time{}, fmt.Errorf("could not parse max updated_at: %q", t.String)
}
// Execution represents a single run of a task.