Repository navigation
perf(web): run the /lore list, plan-usage and invites reads in parallel #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+769
−210
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7bc53b
perf(web): run the /lore list, plan-usage and invites reads in parallel
mthines 8f08fd3
test(web): pin parallel, abortable /lore reads; document the no-serve…
mthines 9c12839
address review comment: keep loaded memories when Load more fails
mthines 6f6beca
address review comment: list every remaining server-action read in we…
mthines 6e9ffbe
chore: simplify pass (mechanical refactors)
mthines 99483b8
address review comment: track lore.results_paged only when a page is …
mthines 3201be9
address review comment: count Load more only when exactly the request…
mthines 659361a
chore(web): update Storybook visual baselines
github-actions[bot] abb2666
ci: re-run checks on the regenerated visual baselines
mthines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Binary file modified
BIN
+50.3 KB
(180%)
...shboard)/lore/__screenshots__/LorePage.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.28 KB
(100%)
...dashboard)/lore/__screenshots__/LorePage.stories.tsx/Empty-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { listPendingInvitesForMe } from '@/lib/org-invites'; | ||
|
|
||
| /** | ||
| * GET /api/invites/pending | ||
| * | ||
| * Pending org invites addressed to the caller — `listPendingInvitesForMe` over | ||
| * HTTP, for the shared `['pending-invites']` query behind the top bar's invites | ||
| * badge, the `/lore` banner and the Organization nav badge. Those used to call | ||
| * the server action directly. Next's router runs server actions one at a time | ||
| * per client, so on `/lore` this read sat in a queue with the plan-usage read | ||
| * and the Explorer's list on every load and every window focus. As a route | ||
| * handler it is an ordinary request that runs in parallel and the browser can | ||
| * abort. | ||
| * | ||
| * Same contract as the action: `[]` when there is no session or the query | ||
| * fails. Never cached: accepting or declining elsewhere must show up on the | ||
| * next refetch. | ||
| */ | ||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| export async function GET() { | ||
| const invites = await listPendingInvitesForMe(); | ||
| return NextResponse.json(invites, { headers: { 'Cache-Control': 'no-store' } }); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { getPlanUsage } from '@/lib/plan'; | ||
|
|
||
| /** | ||
| * GET /api/plan/usage | ||
| * | ||
| * The caller's plan and active memory count — `getPlanUsage` over HTTP, for the | ||
| * top bar's memory badge (`useMemoryTotal`). The badge used to call the server | ||
| * action directly. Next's router runs server actions one at a time per client, | ||
| * so on `/lore` it led a queue that the pending-invites read and the Explorer's | ||
| * list waited behind on every load and every window focus. As a route handler | ||
| * it is an ordinary request that runs in parallel and the browser can abort. | ||
| * | ||
| * Same contract as the action: `null` when there is no session or the RPC | ||
| * fails, and the badge degrades to 0. Never cached, because the count moves | ||
| * whenever an agent writes. | ||
| */ | ||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| export async function GET() { | ||
| const usage = await getPlanUsage(); | ||
| return NextResponse.json(usage, { headers: { 'Cache-Control': 'no-store' } }); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * `GET /api/plan/usage` and `GET /api/invites/pending` are transports, not new | ||
| * logic: each wraps an existing server function so the browser can read it as | ||
| * an ordinary, parallel, abortable request instead of a queued server action. | ||
| * Pinned here: they answer exactly what the function returns (including its | ||
| * signed-out / failure shape) and are never cached. | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const getPlanUsage = vi.fn(); | ||
| const listPendingInvitesForMe = vi.fn(); | ||
|
|
||
| vi.mock('@/lib/plan', () => ({ getPlanUsage: () => getPlanUsage() })); | ||
| vi.mock('@/lib/org-invites', () => ({ | ||
| listPendingInvitesForMe: () => listPendingInvitesForMe(), | ||
| })); | ||
|
|
||
| const planUsageRoute = await import('./plan/usage/route'); | ||
| const pendingInvitesRoute = await import('./invites/pending/route'); | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('GET /api/plan/usage', () => { | ||
| it('answers the caller plan usage as JSON, uncached', async () => { | ||
| getPlanUsage.mockResolvedValue({ count: 3318, limit: 5000, plan: 'free' }); | ||
|
|
||
| const response = await planUsageRoute.GET(); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.headers.get('cache-control')).toBe('no-store'); | ||
| await expect(response.json()).resolves.toEqual({ count: 3318, limit: 5000, plan: 'free' }); | ||
| }); | ||
|
|
||
| it('answers null when there is no session or the RPC failed, as the action did', async () => { | ||
| getPlanUsage.mockResolvedValue(null); | ||
|
|
||
| const response = await planUsageRoute.GET(); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| await expect(response.json()).resolves.toBeNull(); | ||
| }); | ||
|
|
||
| it('is rendered per request, never statically', () => { | ||
| expect(planUsageRoute.dynamic).toBe('force-dynamic'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('GET /api/invites/pending', () => { | ||
| it('answers the invites addressed to the caller as JSON, uncached', async () => { | ||
| const invites = [{ id: 'inv-1', org_id: 'org-1', status: 'pending', org: { name: 'Acme', slug: 'acme' } }]; | ||
| listPendingInvitesForMe.mockResolvedValue(invites); | ||
|
|
||
| const response = await pendingInvitesRoute.GET(); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.headers.get('cache-control')).toBe('no-store'); | ||
| await expect(response.json()).resolves.toEqual(invites); | ||
| }); | ||
|
|
||
| it('answers [] when there is no session or the query failed, as the action did', async () => { | ||
| listPendingInvitesForMe.mockResolvedValue([]); | ||
|
|
||
| await expect((await pendingInvitesRoute.GET()).json()).resolves.toEqual([]); | ||
| }); | ||
|
|
||
| it('is rendered per request, never statically', () => { | ||
| expect(pendingInvitesRoute.dynamic).toBe('force-dynamic'); | ||
| }); | ||
| }); |
Binary file modified
BIN
-288 Bytes
(99%)
...ents/blog/__screenshots__/BlogPostCard.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-361 Bytes
(99%)
...s/blog/__screenshots__/BlogPostCard.stories.tsx/Playground-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.14 KB
(96%)
...onents/blog/__screenshots__/LikeButton.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-124 Bytes
(99%)
...nts/blog/__screenshots__/LikeButton.stories.tsx/Playground-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+43 Bytes
(100%)
...onents/blog/__screenshots__/TocList.stories.tsx/Playground-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-127 Bytes
(99%)
...mand/__screenshots__/CommandPaletteFab.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.79 KB
(91%)
...shboard/__screenshots__/AgentBreakdown.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-38 Bytes
(100%)
...eenshots__/AgentBreakdown.stories.tsx/No-Agent-Family-Data-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-4.69 KB
(89%)
.../dashboard/__screenshots__/UsageHealth.stories.tsx/Default-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-205 Bytes
(99%)
...eenshots__/UsageHealth.stories.tsx/No-Friction-Or-Coverage-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.