Repository navigation
perf(topics): collapse 6 serialized topic-detail server actions into one - #338
Merged
Merged
Conversation
…nto one The topic detail page fired six server-action calls from the client in a Promise.all. Next.js runs server actions sequentially (each is its own queued POST), so the wait was ~the sum of all six, not the slowest — the dominant cost of the slow-feeling page (#312). - Add getTopicDetail(brandId, topicId) in actions/tracking.ts: one server action whose body runs the six reads in a real server-side Promise.all (genuinely parallel, one round trip) and returns a single bundle { topic, summary, trend, sov, competitors, results }. - Add getTopicById(brandId, topicId) in actions/topic.ts and use it instead of getTopics() — fetch only the one topic's row rather than the whole topics list just to read one name. - Page now calls the single action and unpacks the bundle. Output is identical to before — this is a performance refactor, not a behaviour change. Closes #312 (core fix; the stretch items — shared prompt_results scan, progressive render, aggregate caching — remain optional follow-ups).
There was a problem hiding this comment.
Pull request overview
This PR improves perceived performance on the topic detail page (/dashboard/topics/[id]) by reducing client-initiated server action round trips from six serialized calls to a single consolidated server action that runs the underlying reads in a server-side Promise.all.
Changes:
- Added
getTopicDetail(brandId, topicId)intracking.tsto fetch all topic-detail data in one server action call. - Added
getTopicById(brandId, topicId)intopic.tsto avoid fetching the full topics list just to resolve a single topic name. - Updated the topic detail page to call
getTopicDetailand unpack the returned bundle.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
web/src/lib/actions/tracking.ts |
Adds a consolidated getTopicDetail server action and bundles the six reads into one call. |
web/src/lib/actions/topic.ts |
Adds getTopicById helper to fetch only the requested topic row. |
web/src/app/[locale]/(dashboard)/dashboard/topics/[id]/page.tsx |
Switches client fetching logic from six actions to the single bundled action. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…review) - getTopicById now filters is_active = true, matching getTopics() which the page used before via .find() over the active list. Without it an inactive topic (previously "not found") would render — a behavior change. Also narrows the select to the columns mapTopicRow reads. - Switch the cross-action import to the `@/lib/actions/topic` alias to match the convention used elsewhere (e.g. prompt-suggestions.ts). Addresses the Copilot review on #338.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The topic detail page (
/dashboard/topics/[id]) felt slow because it fired six server-action calls from the client inside onePromise.all. Next.js runs server actions sequentially (each is its own queued POST), so the wait was ~the sum of all six, not the slowest — the dominant cost (#312).This collapses them into one server action whose body runs the reads in a real server-side
Promise.all(genuinely parallel, one round trip).Changes
actions/tracking.ts— addgetTopicDetail(brandId, topicId): one action that runs the six reads in a server-sidePromise.alland returns a single bundle{ topic, summary, trend, sov, competitors, results }(newTopicDetailDatatype).actions/topic.ts— addgetTopicById(brandId, topicId); the page now fetches only the one topic's row instead ofgetTopics()(whole list) just to read one name.topics/[id]/page.tsx— calls the single action and unpacks the bundle; the six imports drop to one.Output is identical to before — this is a performance refactor, not a behaviour change.
Related issue
Closes #312 (the core fix). The stretch items in the issue — sharing the single
prompt_resultsscan across summary/competitors/prompt rollup, per-section progressive render, and reading from the*_aggregatestables / short-TTL cache — are left as optional follow-ups.Type of change
refactor— Code change that neither fixes a bug nor adds a feature (performance)How to test
/dashboard/topics; the detail page renders meaningfully faster (one round trip instead of six serialized ones).yarn typecheck,yarn lint,yarn format:check,yarn testall pass fromweb/.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (fromweb/)yarn typecheckpasses (fromweb/)yarn format:checkpasses (fromweb/)