mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-15 08:10:13 +00:00
perf: run async operations in parallel in server load functions
This commit is contained in:
@@ -4,23 +4,21 @@ import UserService from '$lib/services/user-service';
|
|||||||
import type { LayoutServerLoad } from './$types';
|
import type { LayoutServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: LayoutServerLoad = async ({ cookies }) => {
|
export const load: LayoutServerLoad = async ({ cookies }) => {
|
||||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const accessToken = cookies.get(ACCESS_TOKEN_COOKIE_NAME);
|
||||||
const appConfigService = new AppConfigService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const userService = new UserService(accessToken);
|
||||||
|
const appConfigService = new AppConfigService(accessToken);
|
||||||
|
|
||||||
const user = await userService
|
const userPromise = userService.getCurrent().catch(() => null);
|
||||||
.getCurrent()
|
|
||||||
.then((user) => user)
|
const appConfigPromise = appConfigService.list().catch((e) => {
|
||||||
.catch(() => null);
|
console.error(
|
||||||
|
`Failed to get application configuration: ${e.response?.data.error || e.message}`
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
const [user, appConfig] = await Promise.all([userPromise, appConfigPromise]);
|
||||||
|
|
||||||
const appConfig = await appConfigService
|
|
||||||
.list()
|
|
||||||
.then((config) => config)
|
|
||||||
.catch((e) => {
|
|
||||||
console.error(
|
|
||||||
`Failed to get application configuration: ${e.response?.data.error || e.message}`
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
appConfig
|
appConfig
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ import WebAuthnService from '$lib/services/webauthn-service';
|
|||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ cookies }) => {
|
export const load: PageServerLoad = async ({ cookies }) => {
|
||||||
const webauthnService = new WebAuthnService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const accessToken = cookies.get(ACCESS_TOKEN_COOKIE_NAME);
|
||||||
const userService = new UserService(cookies.get(ACCESS_TOKEN_COOKIE_NAME));
|
const webauthnService = new WebAuthnService(accessToken);
|
||||||
const account = await userService.getCurrent();
|
const userService = new UserService(accessToken);
|
||||||
const passkeys = await webauthnService.listCredentials();
|
|
||||||
|
const [account, passkeys] = await Promise.all([
|
||||||
|
userService.getCurrent(),
|
||||||
|
webauthnService.listCredentials()
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
passkeys
|
passkeys
|
||||||
|
|||||||
Reference in New Issue
Block a user