fix compaction sorting and missing live lookups

This commit is contained in:
Charlotte Som 2024-11-28 06:08:02 +02:00
parent c539a4dc5a
commit 1e0ff83f8b

View file

@ -10,7 +10,9 @@ export const getOperations = async (did: string) => {
const compactedEntries = await Array.fromAsync( const compactedEntries = await Array.fromAsync(
Deno.readDir("./data/plc/compacted") Deno.readDir("./data/plc/compacted")
); );
compactedEntries.sort(); compactedEntries.sort((a, b) =>
a.name < b.name ? -1 : a.name > b.name ? 1 : 0
);
for (const entry of compactedEntries) { for (const entry of compactedEntries) {
const process = new Deno.Command("zstd", { const process = new Deno.Command("zstd", {
args: [ args: [
@ -37,14 +39,18 @@ export const getOperations = async (did: string) => {
await process.status; await process.status;
} }
const f = await Deno.open(`./data/plc/live/${prefix}`, { read: true }); try {
const lines = f.readable const f = await Deno.open(`./data/plc/live/${prefix}`, { read: true });
.pipeThrough(new TextDecoderStream()) const lines = f.readable
.pipeThrough(new TextLineStream()); .pipeThrough(new TextDecoderStream())
for await (const line of lines.values()) { .pipeThrough(new TextLineStream());
const entry = JSON.parse(line) as unknown as ExportEntry; for await (const line of lines.values()) {
if (entry.did !== did) continue; const entry = JSON.parse(line) as unknown as ExportEntry;
operations.push(entry); if (entry.did !== did) continue;
operations.push(entry);
}
} catch (_err) {
// ignore
} }
return operations; return operations;