fix: parallelize search indexing

This commit is contained in:
Jacky Zhao 2024-02-02 00:45:02 -08:00
parent ee868b2d79
commit 18cd58617d

View file

@ -464,8 +464,8 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
searchBar?.addEventListener("input", onType) searchBar?.addEventListener("input", onType)
window.addCleanup(() => searchBar?.removeEventListener("input", onType)) window.addCleanup(() => searchBar?.removeEventListener("input", onType))
await fillDocument(data)
registerEscapeHandler(container, hideSearch) registerEscapeHandler(container, hideSearch)
await fillDocument(data)
}) })
/** /**
@ -475,13 +475,18 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
*/ */
async function fillDocument(data: { [key: FullSlug]: ContentDetails }) { async function fillDocument(data: { [key: FullSlug]: ContentDetails }) {
let id = 0 let id = 0
const promises: Array<Promise<unknown>> = []
for (const [slug, fileData] of Object.entries<ContentDetails>(data)) { for (const [slug, fileData] of Object.entries<ContentDetails>(data)) {
await index.addAsync(id++, { promises.push(
id, index.addAsync(id++, {
slug: slug as FullSlug, id,
title: fileData.title, slug: slug as FullSlug,
content: fileData.content, title: fileData.title,
tags: fileData.tags, content: fileData.content,
}) tags: fileData.tags,
}),
)
} }
return await Promise.all(promises)
} }