package db import ( "database/sql" "errors" "fmt" "github.com/bluesky-social/indigo/atproto/syntax" ) func (d *DB) ObservePullRounds(repoDid syntax.DID, rkey string, rounds int) (bool, error) { var stored int err := d.QueryRow( `select rounds from pull_rounds where repo_did = ? and rkey = ?`, repoDid.String(), rkey, ).Scan(&stored) switch { case errors.Is(err, sql.ErrNoRows): if _, err := d.Exec( `insert into pull_rounds (repo_did, rkey, rounds) values (?, ?, ?)`, repoDid.String(), rkey, rounds, ); err != nil { return false, fmt.Errorf("failed to record pull rounds: %w", err) } return false, nil case err != nil: return false, fmt.Errorf("failed to read pull rounds: %w", err) } if rounds == stored { return false, nil } if _, err := d.Exec( `update pull_rounds set rounds = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now') where repo_did = ? and rkey = ?`, rounds, repoDid.String(), rkey, ); err != nil { return false, fmt.Errorf("failed to update pull rounds: %w", err) } return rounds > stored, nil } func (d *DB) ForgetPullRounds(repoDid syntax.DID, rkey string) error { _, err := d.Exec(`delete from pull_rounds where repo_did = ? and rkey = ?`, repoDid.String(), rkey) return err } func (d *DB) DeletePullRoundsByRepo(repoDid syntax.DID) error { _, err := d.Exec(`delete from pull_rounds where repo_did = ?`, repoDid.String()) return err }