packages.wenpai.net/internal/packages/site_meta.go
Ben Word c8a5ab5e5e
Fix SVN discovery never detecting package changes (#6)
* Fix SVN discovery never detecting package changes

SVN discovery parsed plugin/theme slugs from the HTML listing but never
extracted timestamps (LastCommitted was always nil). After the initial
sync set last_synced_at on all packages, the update query
`last_committed > last_synced_at` could never match — so no package was
ever re-synced, resulting in perpetual "Changed: 0" builds with stale
metadata.

Fix by tracking SVN revision numbers and using the DAV REPORT endpoint
to fetch the changelog between runs:

1. Parse the current SVN revision from the listing page header
2. Store last-seen revision per type in a new site_meta table
3. On each run, fetch the SVN log (REPORT) for revisions since last run
4. Extract changed slugs from the log and mark their last_committed
5. The update step then picks up only packages that actually changed

Also includes:
- Backfill migration setting last_committed = last_synced_at for
  existing rows with NULL last_committed
- 600s timeout for DAV REPORT requests (catch-up runs can be large)
- Skip changelog marking when --limit is set (test/partial runs)
- Error on malformed stored revision instead of silent fallback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix gofmt struct field alignment in svn.go

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 12:06:10 -05:00

32 lines
854 B
Go

package packages
import (
"context"
"database/sql"
"fmt"
)
// GetMeta retrieves a value from site_meta by key. Returns "" if not found.
func GetMeta(ctx context.Context, db *sql.DB, key string) (string, error) {
var value string
err := db.QueryRowContext(ctx, `SELECT value FROM site_meta WHERE key = ?`, key).Scan(&value)
if err == sql.ErrNoRows {
return "", nil
}
if err != nil {
return "", fmt.Errorf("getting site_meta %q: %w", key, err)
}
return value, nil
}
// SetMeta inserts or updates a value in site_meta.
func SetMeta(ctx context.Context, db *sql.DB, key, value string) error {
_, err := db.ExecContext(ctx, `
INSERT INTO site_meta (key, value) VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
key, value)
if err != nil {
return fmt.Errorf("setting site_meta %q: %w", key, err)
}
return nil
}