From 1e0ff83f8b2d8179c5f00d2612d657e522f602e9 Mon Sep 17 00:00:00 2001 From: Charlotte Som Date: Thu, 28 Nov 2024 06:08:02 +0200 Subject: [PATCH] fix compaction sorting and missing live lookups --- get-operations.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/get-operations.ts b/get-operations.ts index 1255011..ac0c295 100644 --- a/get-operations.ts +++ b/get-operations.ts @@ -10,7 +10,9 @@ export const getOperations = async (did: string) => { const compactedEntries = await Array.fromAsync( 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) { const process = new Deno.Command("zstd", { args: [ @@ -37,14 +39,18 @@ export const getOperations = async (did: string) => { await process.status; } - const f = await Deno.open(`./data/plc/live/${prefix}`, { read: true }); - const lines = f.readable - .pipeThrough(new TextDecoderStream()) - .pipeThrough(new TextLineStream()); - for await (const line of lines.values()) { - const entry = JSON.parse(line) as unknown as ExportEntry; - if (entry.did !== did) continue; - operations.push(entry); + try { + const f = await Deno.open(`./data/plc/live/${prefix}`, { read: true }); + const lines = f.readable + .pipeThrough(new TextDecoderStream()) + .pipeThrough(new TextLineStream()); + for await (const line of lines.values()) { + const entry = JSON.parse(line) as unknown as ExportEntry; + if (entry.did !== did) continue; + operations.push(entry); + } + } catch (_err) { + // ignore } return operations;