Skip to content

Stream Redis-backed Spotify data and reserve homepage track space - #174

Merged
nwthomas merged 3 commits into
mainfrom
perf/cache-stream-spotify
Oct 9, 2026
Merged

nwthomas merged 3 commits into
mainfrom
perf/cache-stream-spotify

Conversation

@nwthomas

@nwthomas nwthomas commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

The homepage currently blocks its main content on Spotify and Redis. Move fetching and rendering into a single async SpotifyRecentlyPlayed component behind Suspense so the rest of / streams while the lookup runs.

Keep Redis as the only Spotify cache, retaining its existing one-hour TTL. Read Redis before requesting a Spotify token so cache hits avoid Spotify entirely. Add three-second timeouts per Spotify request and catch lookup failures inside the widget.

Reserve space for the heading and 48 px track row while loading. Limit track text to two lines to keep long titles from shifting content. Collapse the slot when the streamed result is empty or fails; collapsing an empty slot intentionally moves following content upward.

Validation:

  • Full ESLint, TypeScript, formatting, and production build passed (existing configuration/deprecation warnings and a nonfatal Open Graph font-fetch warning remain).
  • Chromium checks against the production build with Redis/Spotify stubs: zero change in the following paragraph position at 375 px and 1280 px widths when a delayed long track arrived; track row remained 48 px tall.
  • Empty-track and Redis-error responses both hid the reserved slot.
  • Stub checks confirmed Redis is read first, cache writes retain the 3,600-second TTL, and a second homepage request performs a Redis read without additional Spotify calls.

These checks use stubs, not live Redis/Spotify credentials or production latency.

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
personal-portfolio Ready Ready Preview Oct 9, 2026 3:37am UTC

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T03:41:42.718785Z 695c53c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nwthomas nwthomas changed the title Cache Spotify data and stream homepage content immediately Stream Redis-backed Spotify data and reserve homepage track space Oct 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 695c53ca11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/utils/spotify.ts
Comment on lines +127 to +129
const cachedTrack = await redis.get<NowPlayingTrack | null>(getSpotifyRecentlyPlayedRedisKey());
if (cachedTrack) {
return cachedTrack;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check optional Spotify credentials before serving the cache

In production, this cache lookup now occurs before confirming that the optional Spotify credentials are configured. If a deployment removes or incompletely configures those variables, an old listening record can continue to be published until the Redis TTL expires; with an empty cache, the disabled widget also performs a needless Redis operation. The previous ordering returned null before touching the cache, so add a local credential-presence check before this lookup without necessarily refreshing the access token.

AGENTS.md reference: AGENTS.md:L95-L97

Useful? React with 👍 / 👎.

Comment thread app/utils/spotify.ts
Comment on lines +75 to +76
if (!res.ok) {
throw new Error(`Spotify request failed (${res.status})`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the recently-played fallback on scope errors

When the refresh token grants user-read-recently-played but not the distinct user-read-currently-playing scope, this optional current-track request can return 403 even though the recently-played request remains authorized; Spotify documents the endpoints with separate required scopes (current track, recent tracks). Throwing here prevents getNowPlaying() from reaching its recently-played fallback, whereas the previous implementation treated a non-OK current-track response as a miss, so preserve that fallback for this case.

Useful? React with 👍 / 👎.

@nwthomas
nwthomas merged commit f104457 into main Oct 9, 2026
3 checks passed
@nwthomas
nwthomas deleted the perf/cache-stream-spotify branch October 9, 2026 03:41

This branch was successfully deployed

1 active deployment
Preview — 695c53ca Deployed Oct 9, 2026 by vercel[bot]
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