Merge branch 'pipeline-stats' into 'main'

pipeline: insert event even if stats fail

Closes #221 and #227

See merge request soapbox-pub/ditto!517
This commit is contained in:
Alex Gleason 2024-09-24 21:54:32 +00:00
commit be88e0bc2e

View file

@ -135,10 +135,20 @@ 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 });
} else {
throw e;
}
}
}
/** Parse kind 0 metadata and track indexes in the database. */