Skip to content

feat(api): updated_since change feed for GET /v1/bookings (#262) - #281

Open
dominik-myszkowski wants to merge 2 commits into
Calnode:mainfrom
dominik-myszkowski:feat/bookings-updated-since
Open

dominik-myszkowski wants to merge 2 commits into
Calnode:mainfrom
dominik-myszkowski:feat/bookings-updated-since

Conversation

@dominik-myszkowski

Copy link
Copy Markdown
Contributor

Implements #262: a change feed on GET /v1/bookings, so a poller can sync exactly what changed instead of refetching the whole window and inferring cancellations from bookings disappearing.

What it does

  • GET /v1/bookings?updated_since=<RFC 3339> returns every booking changed at or after that instant, ordered by (updated_at, id) ascending, with updated_at on each item.
  • after_id=<id of the last item> makes the bound an exact keyset cursor: (updated_at, id) > (updated_since, after_id). Without it the bound is inclusive, so boundary rows come back rather than getting lost.
  • Combines with the existing filters and with limit/offset. order=desc and after_id without updated_since are refused with 400.

Your conditions

  1. Cancelled bookings are included. updated_since lifts the default status != 'cancelled' exclusion. An explicit status still narrows.
  2. Every mutation bumps updated_at. The audit found that only 5 of the 23 UPDATEs on bookings set it. Payment transitions, the worker releasing an unpaid hold (a cancellation), meeting links in location_value, confirm_failed, invite fields and RSVPs did not. Fixing each call site would only hold until the next one is added, so migration 00075 hands the column to triggers instead: any UPDATE of a booking, or of its attendee's RSVP, stamps it whatever the statement set.
  3. (updated_at, id) cursor. The column used to mix the DEFAULT's millisecond form with Go's RFC3339Nano, which don't sort lexicographically (. < Z). 00075 normalises existing rows to whole-second RFC 3339, the same string the API returns, so an item's updated_at can be passed back verbatim. Whole seconds produce ties, which id breaks. The current second is held back (updated_at < now), so a tie group is complete before anyone sees it. The cost is that a change appears up to about a second late.
  4. Works with limit/offset, and the index (updated_at, id) serves both the order and the keyset condition.
  5. Documented next to webhooks. ARCHITECTURE §9 describes the feed, and §13 now points webhook consumers to it as catch-up for missed deliveries.

Migration number

00075, following your note on #273 and #275 (00073 is #273's, 00074 is #275's). If the merge order changes, I'll renumber.

Interaction with #280 (erasure delete)

A hard-deleted booking leaves no row, so it never appears in the feed. An upcoming booking has to be cancelled first, so the feed has already reported the cancellation. ARCHITECTURE says so explicitly.

Tests

  • booking:
    • UPDATEs that previously left the column alone (hold released, payment, meeting link, RSVP), and one that writes a stale value explicitly, all move updated_at, always in whole-second form;
    • the feed includes cancelled bookings, in update order;
    • the cursor walks a group of ties on one updated_at exactly once across pages;
    • the current second is held back.
  • handler: the parameters end to end, plus the 400s (bad timestamp, order=desc, after_id alone).

gofmt, go vet ./..., go build ./..., go test ./... and go run ./cmd/i18n-coverage pass locally. The change has no UI part. CHANGELOG has an Added entry.

GET /v1/bookings?updated_since=<RFC 3339> returns every booking changed at
or after that instant, cancelled ones included, ordered by (updated_at, id).
after_id (the last item's id) turns it into an exact keyset cursor, so ties
on updated_at are neither repeated nor skipped. Combines with the existing
filters and limit/offset.

updated_at could not carry this before: only 5 of 23 UPDATEs on bookings
set it (payment transitions, the worker releasing unpaid holds, meeting
links and RSVPs did not), and the column mixed the DEFAULT's millisecond
form with Go's RFC3339Nano, which don't sort lexicographically. Migration
00075 normalises existing values to whole-second RFC 3339 (the string the
API returns), adds an (updated_at, id) index, and hands the column to
triggers: any UPDATE of a booking, or of its attendee's RSVP, stamps it.

The feed holds back the current second, so a later write in that second
can't sort in behind a cursor already handed out.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one edge case worth a look.

Approach: sound — a (updated_at, id) keyset is the right cursor, and handing updated_at to triggers is the right call: it closes the "the next UPDATE forgets the column" hole that a per-call-site fix would reopen, and 00075 normalises the mixed timestamp formats that made the column unorderable to begin with.

Reviewed changes

  • Change feed on GET /v1/bookings — updated_since/after_id build the keyset predicate and (updated_at, id) ordering in booking.List; the default cancelled exclusion is lifted for feed listings; order=desc and a bare after_id are refused.
  • Trigger-owned updated_at — migration 00075 normalises every existing row to whole-second RFC 3339, adds (updated_at, id), and installs insert/update triggers on bookings plus an RSVP trigger on booking_attendees, so no write path can leave the column behind.
  • Whole-second write paths — Cancel, CancelByID, CancelByToken, Reschedule and ReassignHost switch from RFC3339Nano to sqlTime, matching what the triggers and the API return.
  • Tests — booking-level coverage for trigger bumps, cancelled inclusion, tie-walking and the held-back second; handler-level coverage for the feed over HTTP and the new 400s.
  • Docs — ARCHITECTURE §9/§13 and CHANGELOG describe the feed and its role as webhook catch-up.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/booking/list.go Resolved
A client that seeds its cursor from a zero time value sends
0001-01-01T00:00:00Z, which booking.ListFilter reads as no feed at all:
the request got the plain listing, cancelled bookings left out, and
after_id was refused. Clamp anything before the Unix epoch to it.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (since the prior pullfrog review of 7084cd6)

  • Pre-epoch updated_since is clamped to the Unix epoch — parseBookingListFilter now normalises any parsed instant before 1970-01-01T00:00:00Z, so a client seeding its cursor from a zero time.Time (0001-01-01T00:00:00Z) gets a real feed — cancelled bookings included, after_id accepted — instead of silently falling back to the ordinary listing. Since no row can carry an updated_at earlier than the epoch, the result set is unchanged.
  • Regression test — TestListBookings_updatedSinceZeroInstantIsStillAFeed asserts both halves: the zero instant returns the cancelled booking, and pairing it with after_id returns 200 rather than after_id requires updated_since. Verified it fails without the clamp.

The invariant this relies on is now "a supplied updated_since is never the zero time.Time", which the clamp establishes for every HTTP caller; the existing IsZero() presence tests in feed() and the after_id branch are consequently reachable only when the parameter is absent. go test ./internal/handler -run TestListBookings, gofmt -l and go vet ./internal/handler/ are clean on f27efd3.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

shockalotti added a commit that referenced this pull request Dec 1, 2026
#281 holds 00075, and the queue runs 00076 #283, 00077 #285, 00078 #286.
This must merge after those, so it takes 00079. A lower number landing later
leaves a gap and goose refuses to boot.
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