pipeline: insert event even if stats fail

This commit is contained in:
Alex Gleason 2024-09-24 16:15:26 -05:00
parent d72ec843cf
commit 3469374d8e
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -135,10 +135,18 @@ async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise<unde
if (NKinds.ephemeral(event.kind)) return;
const store = await Storages.db();
try {
await store.transaction(async (store, kysely) => {
await updateStats({ event, store, kysely }).catch((e) => console.error(e));
await updateStats({ event, store, kysely });
await store.event(event, { signal });
});
} catch (e) {
// If the failure is only because of updateStats (which runs first), insert the event anyway.
// We can't catch this in the transaction because the error aborts the transaction on the Postgres side.
if (e instanceof Error && e.message.includes('event_stats' satisfies keyof DittoTables)) {
await store.event(event, { signal });
}
}
}
/** Parse kind 0 metadata and track indexes in the database. */