From 595d5a4117fa602dfe09bbf254fe548e1d465938 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Apr 2024 10:43:26 -0500 Subject: [PATCH] Avoid EventDB.count for single row fetches --- src/pipeline.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index 691afdfc..d858cc77 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -48,10 +48,10 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise { - const preexisting = (await cache.count([{ ids: [event.id] }])).count > 0; + const [existing] = await cache.query([{ ids: [event.id], limit: 1 }]); cache.event(event); reqmeister.event(event, { signal }); - return preexisting; + return !!existing; } /** Hydrate the event with the user, if applicable. */ @@ -71,12 +71,12 @@ async function hydrateEvent(event: DittoEvent, signal: AbortSignal): Promise { if (isEphemeralKind(event.kind)) return; - const isDeleted = (await eventsDB.count( + const [deletion] = await eventsDB.query( [{ kinds: [5], authors: [Conf.pubkey, event.pubkey], '#e': [event.id], limit: 1 }], { signal }, - )).count > 0; + ); - if (isDeleted) { + if (deletion) { return Promise.reject(new RelayError('blocked', 'event was deleted')); } else { await Promise.all([