feat(statuspage): refresh pages by checksum
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m46s
ci / test (pull_request) Successful in 14m46s
ci / build (pull_request) Successful in 18m49s
ci / image (pull_request) Successful in 3m24s

Each refresh sent the whole page again even when nothing had changed.
Status page servers now send the checksum of their copy (If-None-Match)
and the API answers 304 when the page, leaving out when it was
generated, is unchanged; the server then only marks its copy current.
The checksum is kept on disk with the page, so it survives restarts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-24 22:57:22 +01:00
1 parent 4e9a198b2f
commit fcf615dce7
6 files changed
+120 -8

No files matched your search

+20 -3
View File
@@ -49,7 +49,9 @@ const (
// Source fetches snapshots; *agentapi.Client implements it.
type Source interface {
Page(ctx context.Context, host, slug string) (agentapi.PageSnapshot, error)
// PageIfChanged answers agentapi.ErrNotModified when the page still
// has checksum.
PageIfChanged(ctx context.Context, host, slug, checksum string) (agentapi.PageSnapshot, error)
Pages(ctx context.Context) ([]agentapi.PageRef, error)
}
@@ -81,6 +83,9 @@ type entry struct {
Slug string `json:"slug,omitempty"`
Snap agentapi.PageSnapshot `json:"snapshot"`
Fetched time.Time `json:"fetched"`
// Checksum is the snapshot's, sent so the API can answer that nothing
// changed instead of sending it again.
Checksum string `json:"checksum,omitempty"`
}
// Options configure a Server.
@@ -330,8 +335,20 @@ func (s *Server) lookup(ctx context.Context, key, host, slug string) (entry, boo
}
func (s *Server) fetch(ctx context.Context, key, host, slug string) (entry, bool) {
snap, err := s.src.Page(ctx, host, slug)
s.mu.Lock()
old, known := s.cache[key]
s.mu.Unlock()
snap, err := s.src.PageIfChanged(ctx, host, slug, old.Checksum)
switch {
case errors.Is(err, agentapi.ErrNotModified) && known:
// Unchanged: the copy is current as of now.
old.Fetched = s.now()
old.Snap.GeneratedAt = old.Fetched
s.mu.Lock()
s.cache[key] = old
s.mu.Unlock()
s.persist(old)
return old, true
case errors.Is(err, agentapi.ErrNotFound):
s.forget(key)
return entry{}, false
@@ -342,7 +359,7 @@ func (s *Server) fetch(ctx context.Context, key, host, slug string) (entry, bool
s.mu.Unlock()
return e, ok
}
e := entry{Key: key, Host: host, Slug: slug, Snap: snap, Fetched: s.now()}
e := entry{Key: key, Host: host, Slug: slug, Snap: snap, Fetched: s.now(), Checksum: snap.Checksum()}
s.mu.Lock()
s.cache[key] = e
s.mu.Unlock()