Skip to content

Commit 6c19b7e

Browse files
committed
fix(perf): optimize exercise app loading with Promise.all for improved performance
1 parent 5f276f2 commit 6c19b7e

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

  • packages/workshop-app/app/routes/_app+/exercise+/$exerciseNumber_.$stepNumber.$type+

packages/workshop-app/app/routes/_app+/exercise+/$exerciseNumber_.$stepNumber.$type+/index.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
5050
})
5151
const searchParams = new URL(request.url).searchParams
5252
const cacheOptions = { request, timings }
53-
const exerciseStepApp = await requireExerciseApp(params, cacheOptions)
53+
54+
const [exerciseStepApp, allAppsFull, problemApp, solutionApp] =
55+
await Promise.all([
56+
requireExerciseApp(params, cacheOptions),
57+
getApps(cacheOptions),
58+
getExerciseApp({ ...params, type: 'problem' }, cacheOptions),
59+
getExerciseApp({ ...params, type: 'solution' }, cacheOptions),
60+
])
61+
62+
const playgroundApp = allAppsFull.find(isPlaygroundApp)
5463
const reqUrl = new URL(request.url)
5564

5665
const pathnameParam = reqUrl.searchParams.get('pathname')
@@ -59,22 +68,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
5968
throw redirect(reqUrl.toString())
6069
}
6170

62-
const problemApp = await getExerciseApp(
63-
{ ...params, type: 'problem' },
64-
cacheOptions,
65-
)
66-
const solutionApp = await getExerciseApp(
67-
{ ...params, type: 'solution' },
68-
cacheOptions,
69-
)
70-
71-
if (!problemApp && !solutionApp) {
72-
throw new Response('Not found', { status: 404 })
73-
}
74-
75-
const allAppsFull = await getApps(cacheOptions)
76-
const playgroundApp = allAppsFull.find(isPlaygroundApp)
77-
7871
const app1Name = reqUrl.searchParams.get('app1')
7972
const app2Name = reqUrl.searchParams.get('app2')
8073
const app1 = app1Name

0 commit comments

Comments
 (0)