@@ -31,6 +31,7 @@ import {
31
31
import type { ModalTranslations } from ' ../../../../types/local-search'
32
32
import { pathToFile } from ' ../../app/utils'
33
33
import { useData } from ' ../composables/data'
34
+ import { LRUCache } from ' ../support/lru'
34
35
import { createTranslate } from ' ../support/translation'
35
36
36
37
const emit = defineEmits <{
@@ -142,6 +143,8 @@ const mark = computedAsync(async () => {
142
143
return markRaw (new Mark (resultsEl .value ))
143
144
}, null )
144
145
146
+ const cache = new LRUCache <string , Map <string , string >>(16 ) // 16 files
147
+
145
148
debouncedWatch (
146
149
() => [searchIndex .value , filterText .value , showDetailedList .value ] as const ,
147
150
async ([index , filterTextValue , showDetailedListValue ], old , onCleanup ) => {
@@ -163,13 +166,12 @@ debouncedWatch(
163
166
? await Promise .all (results .value .map ((r ) => fetchExcerpt (r .id )))
164
167
: []
165
168
if (canceled ) return
166
- const c = new Map <string , Map <string , string >>()
167
169
for (const { id, mod } of mods ) {
168
170
const mapId = id .slice (0 , id .indexOf (' #' ))
169
- let map = c .get (mapId )
171
+ let map = cache .get (mapId )
170
172
if (map ) continue
171
173
map = new Map ()
172
- c .set (mapId , map )
174
+ cache .set (mapId , map )
173
175
const comp = mod .default ?? mod
174
176
if (comp ?.render || comp ?.setup ) {
175
177
const app = createApp (comp )
@@ -209,7 +211,7 @@ debouncedWatch(
209
211
210
212
results .value = results .value .map ((r ) => {
211
213
const [id, anchor] = r .id .split (' #' )
212
- const map = c .get (id )
214
+ const map = cache .get (id )
213
215
const text = map ?.get (anchor ) ?? ' '
214
216
for (const term in r .match ) {
215
217
terms .add (term )
0 commit comments