Skip to content

Commit

Permalink
avoid calling await parent() multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
mishig25 committed Feb 23, 2024
1 parent 4fb5271 commit 1d5994f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/routes/settings/assistants/[assistantId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,8 @@ async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
return assistant;
}

export async function load({ parent, params, locals }) {
const data = await parent();

export async function load({ params, locals }) {
const assistantId = params.assistantId;

const assistant = data.settings.assistants.find((id) => id === assistantId);
if (!assistant) {
throw redirect(302, `${base}/assistant/${params.assistantId}`);
}

let isReported = false;

const createdBy = locals.user?._id ?? locals.sessionId;
Expand Down
14 changes: 14 additions & 0 deletions src/routes/settings/assistants/[assistantId]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { base } from "$app/paths";
import { redirect } from "@sveltejs/kit";

export async function load({ parent, params }) {
const data = await parent();

const assistant = data.settings.assistants.find((id) => id === params.assistantId);

if (!assistant) {
throw redirect(302, `${base}/assistant/${params.assistantId}`);
}

return data;
}

0 comments on commit 1d5994f

Please sign in to comment.