mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-29 10:04:23 +01:00
stats: use the NPostgres transaction method to avoid transactions within transactions
This commit is contained in:
@@ -117,9 +117,8 @@ async function hydrateEvent(event: DittoEvent, signal: AbortSignal): Promise<voi
|
||||
async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise<undefined> {
|
||||
if (NKinds.ephemeral(event.kind)) return;
|
||||
const store = await Storages.db();
|
||||
const kysely = await Storages.kysely();
|
||||
|
||||
await kysely.transaction().execute(async (kysely) => {
|
||||
await store.transaction(async (store, kysely) => {
|
||||
await updateStats({ event, store, kysely });
|
||||
await store.event(event, { signal });
|
||||
});
|
||||
|
||||
@@ -316,6 +316,10 @@ class EventsDB implements NStore {
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
async transaction(callback: (store: NPostgres, kysely: Kysely<DittoTables>) => Promise<void>): Promise<void> {
|
||||
return this.store.transaction((store, kysely) => callback(store, kysely as unknown as Kysely<DittoTables>));
|
||||
}
|
||||
}
|
||||
|
||||
export { EventsDB };
|
||||
|
||||
Reference in New Issue
Block a user