Spaces:
Build error
Build error
fix: alleviate search performance issue
Browse files
backend/functions/src/cloud-functions/searcher.ts
CHANGED
|
@@ -325,6 +325,7 @@ export class SearcherHost extends RPCHost {
|
|
| 325 |
return;
|
| 326 |
}
|
| 327 |
const urls = searchResults.map((x) => new URL(x.url));
|
|
|
|
| 328 |
for await (const scrapped of this.crawler.scrapMany(urls, options, crawlerOptions)) {
|
| 329 |
const mapped = scrapped.map((x, i) => {
|
| 330 |
const upstreamSearchResult = searchResults[i];
|
|
@@ -336,9 +337,13 @@ export class SearcherHost extends RPCHost {
|
|
| 336 |
content: ['html', 'text', 'screenshot'].includes(mode) ? undefined : ''
|
| 337 |
};
|
| 338 |
}
|
|
|
|
|
|
|
|
|
|
| 339 |
return this.crawler.formatSnapshot(mode, x, urls[i]).then((r) => {
|
| 340 |
r.title ??= upstreamSearchResult.title;
|
| 341 |
r.description = upstreamSearchResult.description;
|
|
|
|
| 342 |
|
| 343 |
return r;
|
| 344 |
}).catch((err) => {
|
|
|
|
| 325 |
return;
|
| 326 |
}
|
| 327 |
const urls = searchResults.map((x) => new URL(x.url));
|
| 328 |
+
const snapshotMap = new WeakMap();
|
| 329 |
for await (const scrapped of this.crawler.scrapMany(urls, options, crawlerOptions)) {
|
| 330 |
const mapped = scrapped.map((x, i) => {
|
| 331 |
const upstreamSearchResult = searchResults[i];
|
|
|
|
| 337 |
content: ['html', 'text', 'screenshot'].includes(mode) ? undefined : ''
|
| 338 |
};
|
| 339 |
}
|
| 340 |
+
if (snapshotMap.has(x)) {
|
| 341 |
+
return snapshotMap.get(x);
|
| 342 |
+
}
|
| 343 |
return this.crawler.formatSnapshot(mode, x, urls[i]).then((r) => {
|
| 344 |
r.title ??= upstreamSearchResult.title;
|
| 345 |
r.description = upstreamSearchResult.description;
|
| 346 |
+
snapshotMap.set(x, r);
|
| 347 |
|
| 348 |
return r;
|
| 349 |
}).catch((err) => {
|