Skip to content

Commit

Permalink
Polish desc shards index format
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Jun 22, 2024
1 parent 9afa9f7 commit 28832f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion extension/index-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import rfcsIndex from "./index/rfcs.js";
import rustcIndex from "./index/rustc.js";
import targetsIndex from "./index/targets.js";
import searchIndex from "./index/std-docs.js";
import stdDescShards from "./index/desc-shards/std.js";
import { mapping, crateIndex } from "./index/crates.js";
import storage from "./core/storage.js";
import IndexSetter from "./index-setter.js";
Expand All @@ -29,7 +30,12 @@ export default class IndexManager extends IndexSetter {
}

static async getDescShards(crate) {
return await storage.getItem(`desc-shards-${crate}`) || {};
let descShards = await storage.getItem(`desc-shards-${crate}`);
if (descShards) {
return new Map(descShards);
} else {
return stdDescShards;
}
}

static async getBookIndex() {
Expand Down
3 changes: 2 additions & 1 deletion extension/index/desc-shards/std.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions extension/script/add-search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
async function loadDescShard(...crates) {
if (!window.searchState.descShards) return null;

let crateDescsShard = {};
// Use [[crateName, shards]] array to construct a map.
let crateDescsShard = [];
for (let crate of crates) {
let shards = {};
for (let descShard of window.searchState.descShards.get(crate)) {
shards[descShard.shard] = await loadDesc(descShard);
}

crateDescsShard[crate] = shards;
crateDescsShard.push([crate, shards]);
}

console.log('load desc shard:', crateDescsShard);
Expand Down
3 changes: 1 addition & 2 deletions extension/search/docs/desc-shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class DescShardManager {
}

async initDescShards() {
const stdDescShards = await IndexManager.getDescShards('std-stable');
this._descShards = new Map(Object.entries(stdDescShards));
this._descShards = await IndexManager.getDescShards('std-stable');
for (const crate of Object.keys(await CrateDocManager.getCrates())) {
const descShards = await DescShardManager.getDescShards(crate);
this._descShards.set(crate, descShards);
Expand Down

0 comments on commit 28832f2

Please sign in to comment.