Skip to content

Commit 50ab7a2

Browse files
committed
sectionテーブルをrevisionymlと同期、チャットのページ移行が動作することを確認
1 parent 8aa482e commit 50ab7a2

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

app/[lang]/[pageId]/pageContent.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ export function PageContent(props: PageContentProps) {
112112
<div>
113113
{/* 右側に表示するチャット履歴欄 */}
114114
{chatHistories
115-
.filter((c) => c.sectionId === section.id)
115+
.filter(
116+
(c) =>
117+
c.sectionId === section.id ||
118+
// 対象のセクションが存在しないものは、introセクション(index=0)にフォールバックする
119+
(index === 0 &&
120+
dynamicMdContent.every((sec) => c.sectionId !== sec.id))
121+
)
116122
.map(({ chatId, messages }) => (
117123
<div
118124
key={chatId}

app/lib/chatHistory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export async function getChat(
119119
drizzle
120120
.select()
121121
.from(section)
122-
.where(eq(section.pagePath, `${path.lang}/${path.page}`))
122+
.where(and(
123+
eq(section.sectionId, chat.sectionId),
124+
eq(section.pagePath, `${path.lang}/${path.page}`),
125+
))
123126
)
124127
),
125128
with: {
@@ -140,6 +143,7 @@ export async function getChat(
140143
})
141144
);
142145
}
146+
// @ts-expect-error なぜかchatsの型にsectionとmessagesが含まれていないことになっているが、正しくwithを指定しているし、console.logしてみるとちゃんと含まれている
143147
return chats;
144148
}
145149
export async function getChatFromCache(path: PagePath, context: Context) {
@@ -149,6 +153,7 @@ export async function getChatFromCache(path: PagePath, context: Context) {
149153
// cacheされる関数の中でheader()にはアクセスできない。
150154
// なので外でinitContext()を呼んだものを引数に渡す必要がある。
151155
// しかし、drizzleオブジェクトは外から渡せないのでgetChatの中で改めてinitContext()を呼んでdrizzleだけ再初期化している
156+
// こんな意味不明な仕様になっているのはactionから呼ばれる関数とレンダリング時に呼ばれる関数を1ファイルでまとめて定義し共通化しようとしているせい。あとでなんとかする
152157
const { auth, userId } = context;
153158
if (!userId) {
154159
return [];

scripts/updateDocsRevisions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
import yaml from "js-yaml";
99
import { execFileSync } from "node:child_process";
1010
import { existsSync } from "node:fs";
11+
import { getDrizzle } from "@/lib/drizzle";
12+
import { section as sectionTable } from "@/schema/chat";
13+
import { eq } from "drizzle-orm";
14+
import "dotenv/config";
1115

1216
const docsDir = join(process.cwd(), "public", "docs");
1317

@@ -67,6 +71,20 @@ for (const id in revisions) {
6771
}
6872
}
6973

74+
const drizzle = await getDrizzle();
75+
for (const id in revisions) {
76+
await drizzle
77+
.insert(sectionTable)
78+
.values({
79+
sectionId: id,
80+
pagePath: revisions[id].page,
81+
})
82+
.onConflictDoUpdate({
83+
target: sectionTable.sectionId,
84+
set: { pagePath: revisions[id].page },
85+
});
86+
}
87+
7088
const revisionsYml = yaml.dump(revisions, {
7189
sortKeys: true,
7290
noArrayIndent: true,

0 commit comments

Comments
 (0)