mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Update stats in a transaction
This commit is contained in:
parent
1983171193
commit
96af3bb8bf
2 changed files with 15 additions and 14 deletions
|
|
@ -116,8 +116,20 @@ async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise<void
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const kysely = await DittoDB.getInstance();
|
const kysely = await DittoDB.getInstance();
|
||||||
|
|
||||||
await updateStats({ event, store, kysely }).catch(debug);
|
try {
|
||||||
|
await kysely.transaction().execute(async (trx) => {
|
||||||
|
await updateStats({ event, store, kysely: trx });
|
||||||
await store.event(event, { signal });
|
await store.event(event, { signal });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e.message === 'Cannot add a deleted event') {
|
||||||
|
throw new RelayError('blocked', 'event deleted by user');
|
||||||
|
} else if (e.message === 'Cannot replace an event with an older event') {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
debug('ERROR', e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parse kind 0 metadata and track indexes in the database. */
|
/** Parse kind 0 metadata and track indexes in the database. */
|
||||||
|
|
|
||||||
|
|
@ -60,18 +60,7 @@ class EventsDB implements NStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.deleteEventsAdmin(event);
|
await this.deleteEventsAdmin(event);
|
||||||
|
|
||||||
try {
|
|
||||||
await this.store.event(event);
|
await this.store.event(event);
|
||||||
} catch (e) {
|
|
||||||
if (e.message === 'Cannot add a deleted event') {
|
|
||||||
throw new RelayError('blocked', 'event deleted by user');
|
|
||||||
} else if (e.message === 'Cannot replace an event with an older event') {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
this.console.debug('ERROR', e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if an event has been deleted by the admin. */
|
/** Check if an event has been deleted by the admin. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue