fix: batch saved keyword inserts for D1 (#85)
This commit is contained in:
parent
ad3b732f60
commit
e5206ec07b
@ -66,18 +66,20 @@ async function saveKeywordsToProject(params: {
|
|||||||
}) {
|
}) {
|
||||||
if (params.keywords.length === 0) return;
|
if (params.keywords.length === 0) return;
|
||||||
|
|
||||||
await db
|
const [first, ...rest] = params.keywords.map((keyword) =>
|
||||||
|
db
|
||||||
.insert(savedKeywords)
|
.insert(savedKeywords)
|
||||||
.values(
|
.values({
|
||||||
params.keywords.map((keyword) => ({
|
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
projectId: params.projectId,
|
projectId: params.projectId,
|
||||||
keyword,
|
keyword,
|
||||||
locationCode: params.locationCode,
|
locationCode: params.locationCode,
|
||||||
languageCode: params.languageCode,
|
languageCode: params.languageCode,
|
||||||
})),
|
})
|
||||||
)
|
.onConflictDoNothing(),
|
||||||
.onConflictDoNothing();
|
);
|
||||||
|
|
||||||
|
await db.batch([first, ...rest]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listSavedKeywordsByProject(projectId: string) {
|
async function listSavedKeywordsByProject(projectId: string) {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export const researchKeywordsSchema = z.object({
|
|||||||
|
|
||||||
export const saveKeywordsSchema = z.object({
|
export const saveKeywordsSchema = z.object({
|
||||||
projectId: z.string().min(1),
|
projectId: z.string().min(1),
|
||||||
keywords: z.array(z.string().min(1)).min(1).max(200),
|
keywords: z.array(z.string().min(1)).min(1).max(500),
|
||||||
locationCode: z.number().int().positive().default(2840),
|
locationCode: z.number().int().positive().default(2840),
|
||||||
languageCode: z.string().min(2).max(8).default("en"),
|
languageCode: z.string().min(2).max(8).default("en"),
|
||||||
metrics: z
|
metrics: z
|
||||||
@ -54,7 +54,7 @@ export const saveKeywordsSchema = z.object({
|
|||||||
.optional(),
|
.optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.max(200)
|
.max(500)
|
||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user