fix: need to store NodeId not the string form of it

This commit is contained in:
Derrick Hammer 2023-11-17 04:56:19 -05:00
parent 2c39f9fd76
commit 3ad41c75c1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 9 deletions

View File

@ -87,8 +87,8 @@ export class S5Node {
async readStorageLocationsFromDB( async readStorageLocationsFromDB(
hash: Multihash, hash: Multihash,
): Promise<Map<number, Map<string, Map<number, any>>>> { ): Promise<Map<number, Map<NodeId, Map<number, any>>>> {
const map = new Map<number, Map<string, Map<number, any>>>(); const map = new Map<number, Map<NodeId, Map<number, any>>>();
const bytes = await this.db.get(stringifyHash(hash)); const bytes = await this.db.get(stringifyHash(hash));
if (bytes === null) { if (bytes === null) {
return map; return map;
@ -97,15 +97,12 @@ export class S5Node {
const mapLength = unpacker.unpackMapLength(); const mapLength = unpacker.unpackMapLength();
for (let i = 0; i < mapLength; i++) { for (let i = 0; i < mapLength; i++) {
const type = unpacker.unpackInt() as number; const type = unpacker.unpackInt() as number;
const innerMap = new Map<string, Map<number, any>>(); const innerMap = new Map<NodeId, Map<number, any>>();
map.set(type, innerMap); map.set(type, innerMap);
const innerMapLength = unpacker.unpackMapLength(); const innerMapLength = unpacker.unpackMapLength();
for (let j = 0; j < innerMapLength; j++) { for (let j = 0; j < innerMapLength; j++) {
const nodeId = new NodeId(unpacker.unpackBinary()); const nodeId = new NodeId(unpacker.unpackBinary());
innerMap.set( innerMap.set(nodeId, new Map(unpacker.unpackMap() as [number, any][]));
nodeId.toString(),
new Map(unpacker.unpackMap() as [number, any][]),
);
} }
} }
return map; return map;
@ -126,7 +123,7 @@ export class S5Node {
}) { }) {
const map = await this.readStorageLocationsFromDB(hash); const map = await this.readStorageLocationsFromDB(hash);
const innerMap = const innerMap =
map.get(location.type) || new Map<string, Map<number, any>>(); map.get(location.type) || new Map<NodeId, Map<number, any>>();
map.set(location.type, innerMap); map.set(location.type, innerMap);
const locationMap = new Map<number, any>([ const locationMap = new Map<number, any>([
@ -136,7 +133,7 @@ export class S5Node {
[4, message], [4, message],
]); ]);
innerMap.set(nodeId.toString(), locationMap); innerMap.set(nodeId, locationMap);
await config.cacheDb.put( await config.cacheDb.put(
stringifyHash(hash), stringifyHash(hash),
new Packer().pack(map).takeBytes(), new Packer().pack(map).takeBytes(),