about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2025-08-30 12:30:02 -0700
committerMichael Howell <michael@notriddle.com>2025-08-30 20:20:18 -0700
commit6ef0bfdb5cd874502aeaa7339fbe059b91ed35c3 (patch)
tree5db91d394c3487bf0d91fcb230608422967e2f7e
parent0becce400b73dc54754d005e1e4513811043466b (diff)
downloadrust-6ef0bfdb5cd874502aeaa7339fbe059b91ed35c3.tar.gz
rust-6ef0bfdb5cd874502aeaa7339fbe059b91ed35c3.zip
rustdoc-search: improve concurrency at type search
-rw-r--r--src/librustdoc/html/static/js/search.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 2854f65b599..fa812a2b67b 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -4031,7 +4031,11 @@ class DocSearch {
                         return empty_postings_list;
                     }
                     const typeFilter = itemTypeFromName(elem.typeFilter);
-                    const searchResults = await index.search(elem.normalizedPathLast);
+                    const [searchResults, upla, uplb] = await Promise.all([
+                        index.search(elem.normalizedPathLast),
+                        unpackPostingsListAll(elem.generics, polarity),
+                        unpackPostingsListBindings(elem.bindings, polarity),
+                    ]);
                     /**
                      * @type {Promise<[
                      *     number,
@@ -4196,8 +4200,6 @@ class DocSearch {
                         })) {
                             continue;
                         }
-                        const upla = await unpackPostingsListAll(elem.generics, polarity);
-                        const uplb = await unpackPostingsListBindings(elem.bindings, polarity);
                         for (const {invertedIndex: genericsIdx, queryElem: generics} of upla) {
                             for (const {invertedIndex: bindingsIdx, queryElem: bindings} of uplb) {
                                 results.push({
@@ -4303,19 +4305,23 @@ class DocSearch {
                             queryElem: new Map(),
                         }];
                     }
-                    const firstKeyIds = await index.search(firstKey);
+                    // HEADS UP!
+                    // We must put this map back the way we found it before returning,
+                    // otherwise things break.
+                    elems.delete(firstKey);
+                    const [firstKeyIds, firstPostingsList, remainingAll] = await Promise.all([
+                        index.search(firstKey),
+                        unpackPostingsListAll(firstList, polarity),
+                        unpackPostingsListBindings(elems, polarity),
+                    ]);
                     if (!firstKeyIds) {
+                        elems.set(firstKey, firstList);
                         // User specified a non-existent key.
                         return [{
                             invertedIndex: empty_inverted_index,
                             queryElem: new Map(),
                         }];
                     }
-                    elems.delete(firstKey);
-                    const [firstPostingsList, remainingAll] = await Promise.all([
-                        unpackPostingsListAll(firstList, polarity),
-                        unpackPostingsListBindings(elems, polarity),
-                    ]);
                     /** @type {PostingsList<Map<number, rustdoc.QueryElement[]>>[]} */
                     const results = [];
                     for (const keyId of firstKeyIds.matches().entries()) {