Skip to content

Commit 8467c04

Browse files
committed
fetch並列化 & better-authのキャッシュを追加
1 parent b6137f8 commit 8467c04

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

app/[docs_id]/page.tsx

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,48 @@ export default async function Page({
1515
}) {
1616
const { docs_id } = await params;
1717

18-
let mdContent: string;
19-
try {
20-
if (process.env.NODE_ENV === "development") {
21-
mdContent = await readFile(
22-
join(process.cwd(), "public", "docs", `${docs_id}.md`),
23-
"utf-8"
24-
);
25-
} else {
26-
const cfAssets = getCloudflareContext().env.ASSETS;
27-
const mdRes = await cfAssets!.fetch(
28-
`https://assets.local/docs/${docs_id}.md`
29-
);
30-
if (mdRes.ok) {
31-
mdContent = await mdRes.text();
32-
} else {
18+
let mdContent: Promise<string>;
19+
if (process.env.NODE_ENV === "development") {
20+
mdContent = readFile(
21+
join(process.cwd(), "public", "docs", `${docs_id}.md`),
22+
"utf-8"
23+
).catch((e) => {
24+
console.error(e);
25+
notFound();
26+
});
27+
} else {
28+
const cfAssets = getCloudflareContext().env.ASSETS;
29+
mdContent = cfAssets!
30+
.fetch(`https://assets.local/docs/${docs_id}.md`)
31+
.then(async (res) => {
32+
if (!res.ok) {
33+
notFound();
34+
}
35+
return res.text();
36+
})
37+
.catch((e) => {
38+
console.error(e);
3339
notFound();
34-
}
35-
}
36-
} catch (error) {
37-
console.error(error);
38-
notFound();
40+
});
3941
}
40-
41-
mdContent = mdContent.replaceAll(
42-
"{process.env.PYODIDE_PYTHON_VERSION}",
43-
String(pyodideLock.info.python)
42+
mdContent = mdContent.then((text) =>
43+
text.replaceAll(
44+
"{process.env.PYODIDE_PYTHON_VERSION}",
45+
String(pyodideLock.info.python)
46+
)
4447
);
4548

46-
const splitMdContent: MarkdownSection[] = splitMarkdown(mdContent);
49+
const splitMdContent: Promise<MarkdownSection[]> = mdContent.then((text) =>
50+
splitMarkdown(text)
51+
);
4752

48-
const initialChatHistories = await getChat(docs_id);
53+
const initialChatHistories = getChat(docs_id);
4954

5055
return (
51-
<ChatHistoryProvider initialChatHistories={initialChatHistories}>
56+
<ChatHistoryProvider initialChatHistories={await initialChatHistories}>
5257
<PageContent
53-
documentContent={mdContent}
54-
splitMdContent={splitMdContent}
58+
documentContent={await mdContent}
59+
splitMdContent={await splitMdContent}
5560
docs_id={docs_id}
5661
/>
5762
</ChatHistoryProvider>

app/lib/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export async function getAuthServer(
2020
database: drizzleAdapter(drizzle, {
2121
provider: "pg",
2222
}),
23+
session: {
24+
cookieCache: {
25+
enabled: true,
26+
maxAge: 5 * 60,
27+
},
28+
},
2329
plugins: [
2430
anonymous({
2531
onLinkAccount: ({ anonymousUser, newUser }) =>

0 commit comments

Comments
 (0)