Avoid EventDB.count for single row fetches

This commit is contained in:
Alex Gleason 2024-04-08 10:43:26 -05:00
parent 9024ec8655
commit 595d5a4117
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 5 additions and 5 deletions

View File

@ -48,10 +48,10 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
/** Encounter the event, and return whether it has already been encountered. */
async function encounterEvent(event: NostrEvent, signal: AbortSignal): Promise<boolean> {
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<voi
async function storeEvent(event: DittoEvent, signal?: AbortSignal): Promise<void> {
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([