mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Try wrapping slow queries in transaction
This commit is contained in:
parent
fe99e4a053
commit
121de85a84
2 changed files with 19 additions and 12 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { db } from '@/db.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { type DittoFilter } from '@/filter.ts';
|
||||
import * as mixer from '@/mixer.ts';
|
||||
|
|
@ -40,8 +41,10 @@ async function renderStatuses(c: AppContext, filters: DittoFilter<1>[]) {
|
|||
return c.json([]);
|
||||
}
|
||||
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events, statuses);
|
||||
return db.transaction().execute(async () => {
|
||||
const statuses = await Promise.all(events.map((event) => renderStatus(event, c.get('pubkey'))));
|
||||
return paginated(c, events, statuses);
|
||||
})
|
||||
}
|
||||
|
||||
export { hashtagTimelineController, homeTimelineController, publicTimelineController };
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { db } from '@/db.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { addRelays } from '@/db/relays.ts';
|
||||
|
|
@ -21,17 +22,20 @@ import type { EventData } from '@/types.ts';
|
|||
*/
|
||||
async function handleEvent(event: Event): Promise<void> {
|
||||
if (encounterEvent(event)) return;
|
||||
const data = await getEventData(event);
|
||||
|
||||
await Promise.all([
|
||||
storeEvent(event, data),
|
||||
processDeletions(event),
|
||||
trackRelays(event),
|
||||
trackHashtags(event),
|
||||
processMedia(event, data),
|
||||
streamOut(event, data),
|
||||
broadcast(event, data),
|
||||
]);
|
||||
await db.transaction().execute(async () => {
|
||||
const data = await getEventData(event);
|
||||
|
||||
await Promise.all([
|
||||
storeEvent(event, data),
|
||||
processDeletions(event),
|
||||
trackRelays(event),
|
||||
trackHashtags(event),
|
||||
processMedia(event, data),
|
||||
streamOut(event, data),
|
||||
broadcast(event, data),
|
||||
]);
|
||||
})
|
||||
}
|
||||
|
||||
/** Tracks encountered events to skip duplicates, improving idempotency and performance. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue