mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(nvs): share blob series lookup (#17318)
This commit is contained in:
@@ -36,6 +36,23 @@ const entrySource = ({
|
||||
keyId,
|
||||
});
|
||||
|
||||
const seriesFor = <T>(
|
||||
byNamespace: Map<number, Map<string, Map<number, T>>>,
|
||||
item: RawBlobChunk | RawBlobIndex,
|
||||
): Map<number, T> => {
|
||||
let byKey = byNamespace.get(item.namespace_id);
|
||||
if (byKey === undefined) {
|
||||
byKey = new Map();
|
||||
byNamespace.set(item.namespace_id, byKey);
|
||||
}
|
||||
let series = byKey.get(item.keyId);
|
||||
if (series === undefined) {
|
||||
series = new Map();
|
||||
byKey.set(item.keyId, series);
|
||||
}
|
||||
return series;
|
||||
};
|
||||
|
||||
/** Reassemble v2 multi-chunk `BLOB_IDX` + `BLOB_DATA` items and surface orphan chunks. */
|
||||
export const reassembleNvsV2Blobs = async (
|
||||
indices: readonly RawBlobIndex[],
|
||||
@@ -52,16 +69,7 @@ export const reassembleNvsV2Blobs = async (
|
||||
onCheckpoint?.();
|
||||
}
|
||||
const ch = chunks[i]!;
|
||||
let byKey = bestByNsKey.get(ch.namespace_id);
|
||||
if (byKey === undefined) {
|
||||
byKey = new Map<string, Map<number, RawBlobChunk>>();
|
||||
bestByNsKey.set(ch.namespace_id, byKey);
|
||||
}
|
||||
let byChunkIndex = byKey.get(ch.keyId);
|
||||
if (byChunkIndex === undefined) {
|
||||
byChunkIndex = new Map<number, RawBlobChunk>();
|
||||
byKey.set(ch.keyId, byChunkIndex);
|
||||
}
|
||||
const byChunkIndex = seriesFor(bestByNsKey, ch);
|
||||
const existing = byChunkIndex.get(ch.chunkIndex);
|
||||
if (
|
||||
existing === undefined ||
|
||||
@@ -99,16 +107,7 @@ export const reassembleNvsV2Blobs = async (
|
||||
}
|
||||
const idx = indices[i]!;
|
||||
const rangeKey = ((idx.chunkStart & 0xff) << 8) | (idx.chunkCount & 0xff);
|
||||
let cacheByKey = reassemblyCache.get(idx.namespace_id);
|
||||
if (cacheByKey === undefined) {
|
||||
cacheByKey = new Map<string, Map<number, ReassembledBlobSummary>>();
|
||||
reassemblyCache.set(idx.namespace_id, cacheByKey);
|
||||
}
|
||||
let cacheByRange = cacheByKey.get(idx.keyId);
|
||||
if (cacheByRange === undefined) {
|
||||
cacheByRange = new Map<number, ReassembledBlobSummary>();
|
||||
cacheByKey.set(idx.keyId, cacheByRange);
|
||||
}
|
||||
const cacheByRange = seriesFor(reassemblyCache, idx);
|
||||
let summary = cacheByRange.get(rangeKey);
|
||||
if (summary === undefined) {
|
||||
const seriesChunks = sortedByNsKey.get(idx.namespace_id)?.get(idx.keyId);
|
||||
|
||||
Reference in New Issue
Block a user