Skip to content

Commit de1ec72

Browse files
committed
perf: parallel api calls to optimize requests
1 parent 6abfd00 commit de1ec72

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

frontend/src/routes/(app)/q/[name]/+page.server.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,28 @@ import client from '$lib/clients/client';
22
import type { PageServerLoad } from './$types';
33

44
export const load: PageServerLoad = async ({ params }) => {
5-
const {
6-
data: quibs_data,
7-
error: quibs_error,
8-
response: quibs_response
9-
} = await client.GET('/api/v1/quiblets/{name}/quibs/', {
10-
params: {
11-
path: { name: params.name }
12-
}
13-
});
14-
15-
const {
16-
data: highlighted_quibs_data,
17-
error: highlighted_quibs_error,
18-
response: highlighted_quibs_response
19-
} = await client.GET('/api/v1/quiblets/{name}/highlighted_quibs/', {
20-
params: {
21-
path: { name: params.name }
22-
}
23-
});
5+
const [quibs, highlighted_quibs] = await Promise.all([
6+
client.GET('/api/v1/quiblets/{name}/quibs/', {
7+
params: {
8+
path: { name: params.name }
9+
}
10+
}),
11+
client.GET('/api/v1/quiblets/{name}/highlighted_quibs/', {
12+
params: {
13+
path: { name: params.name }
14+
}
15+
})
16+
]);
2417

2518
if (
26-
quibs_response.ok &&
27-
quibs_data &&
28-
highlighted_quibs_response &&
29-
highlighted_quibs_data
19+
quibs.response.ok &&
20+
quibs.data &&
21+
highlighted_quibs.response &&
22+
highlighted_quibs.data
3023
) {
31-
return { quibs: quibs_data, highlighted_quibs: highlighted_quibs_data };
32-
} else if (quibs_error || highlighted_quibs_error) {
33-
console.error(quibs_error, highlighted_quibs_error);
24+
return { quibs: quibs.data, highlighted_quibs: highlighted_quibs.data };
25+
} else {
26+
const errors = [quibs.error, highlighted_quibs.error].filter((error) => error);
27+
console.error(errors);
3428
}
3529
};

0 commit comments

Comments
 (0)