Skip to content

Add public stats endpoint for DanielIbarra.com - #59

Merged
dannysusername merged 2 commits into
mainfrom
newfeature
Nov 9, 2026
Merged

dannysusername merged 2 commits into
mainfrom
newfeature

Conversation

@dannysusername

@dannysusername dannysusername commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

What

GET /api/public/stats: live, anonymous Aviary totals for the new [ LIVE STATS ] panel on danielibarra.com. It returns users, aircraft, flights, hours flown, alerts sent, signups in the last 7 and 30 days, and up to 10 date-only "New pilot joined" lines. Nothing about any one account.

How

  • Security: a separate public chain for /api/public/**. No login, no session, GET only. CORS is allowed only for danielibarra.com (AVIARY_PUBLIC_STATS_ORIGINS). Other origins and POST get 403.
  • Rate limit: 60 calls per IP per 10 minutes, then 429.
  • Cache: the snapshot lives 15 minutes and is recomputed only when requested, one thread at a time. Nothing runs on a timer, so it never wakes Neon by itself. A failed refresh keeps serving the old numbers.
  • Signup dates: new nullable users.created_at, set on first save. Existing accounts stay NULL (no guessed dates). Additive; the note is in docs/migrations/2026-11-09_users_created_at.sql.
  • Every account is counted for now, test accounts included.

Tests

  • 18 new tests: service caching and number shaping, real queries on H2, and endpoint checks (public, no session, CORS allow/deny, POST refused, 429, and a leak check for usernames and tail numbers).
  • ./gradlew test passes.
  • Checked by hand locally with curl and the portfolio panel in a browser.

After merge

  • main auto-deploys to staging.
  • Check https://<staging>/api/public/stats, then promote to production.
  • The portfolio panel goes live separately (DanielIbarra repo).

dannysusername and others added 2 commits November 9, 2026 18:06
GET /api/public/stats returns live, anonymous Aviary totals for the
portfolio's Aviary panel: users, aircraft, flights, hours flown (time in
service), alerts sent, signups in the last 7/30 days, and up to 10
date-only "New pilot joined" lines. Nothing about any one account.

- Public, read-only filter chain for /api/public/**: no login, no
  session, GET only. CORS only for aviary.public-stats.allowed-origins
  (env AVIARY_PUBLIC_STATS_ORIGINS, defaults to danielibarra.com).
- Rate limited to 60 calls per IP per 10 minutes (429 + Retry-After).
- Numbers are cached for 15 minutes and recomputed only on request,
  one thread at a time, so traffic never turns into per-visitor queries
  and nothing wakes Neon on a timer. A failed refresh keeps serving the
  last snapshot; 503 only if none exists yet.
- users.created_at (nullable, set by @PrePersist) records signup dates
  from now on. Existing accounts stay NULL: no guessed dates. Additive;
  migration note in docs/migrations.
- All accounts are counted for now, test accounts included.
- Tests: service caching and shaping, real queries on H2, and endpoint
  checks (public, no session, CORS allow/deny, POST refused, 429, and no
  username or tail number in the body).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M4dsGvpqnWiNuLHPLuGXx4
Linux clocks give nanosecond Instants but the database keeps microseconds,
so a freshly saved account's createdAt didn't match what was read back
(failed in CI, passed on macOS). Truncate when it's set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M4dsGvpqnWiNuLHPLuGXx4
@dannysusername
dannysusername merged commit 0679cca into main Nov 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant