diff --git a/src/db/events.ts b/src/db/events.ts index cb04b23..7910a40 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -119,16 +119,4 @@ async function getFilters( )); } -/** Returns whether the pubkey is followed by a local user. */ -async function isLocallyFollowed(pubkey: string): Promise { - return Boolean( - await getFilterQuery({ - kinds: [3], - '#p': [pubkey], - limit: 1, - local: true, - }).executeTakeFirst(), - ); -} - -export { getFilters, insertEvent, isLocallyFollowed }; +export { getFilters, insertEvent }; diff --git a/src/pipeline.ts b/src/pipeline.ts index 3e2306f..00d3eb9 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -2,6 +2,7 @@ import * as eventsDB from '@/db/events.ts'; import { addRelays } from '@/db/relays.ts'; import { findUser } from '@/db/users.ts'; import { type Event } from '@/deps.ts'; +import { isLocallyFollowed } from '@/queries.ts'; import { trends } from '@/trends.ts'; import { isRelay, nostrDate } from '@/utils.ts'; @@ -19,7 +20,7 @@ async function handleEvent(event: Event): Promise { /** Maybe store the event, if eligible. */ async function storeEvent(event: Event): Promise { - if (await findUser({ pubkey: event.pubkey }) || await eventsDB.isLocallyFollowed(event.pubkey)) { + if (await findUser({ pubkey: event.pubkey }) || await isLocallyFollowed(event.pubkey)) { await eventsDB.insertEvent(event).catch(console.warn); } } diff --git a/src/queries.ts b/src/queries.ts index 7d03c30..0f4b3ec 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -1,8 +1,8 @@ +import * as eventsDB from '@/db/events.ts'; import { type Event, type Filter, findReplyTag } from '@/deps.ts'; +import * as mixer from '@/mixer.ts'; import { type PaginationParams } from '@/utils.ts'; -import * as mixer from './mixer.ts'; - interface GetEventOpts { /** Timeout in milliseconds. */ timeout?: number; @@ -83,4 +83,10 @@ function getDescendants(eventId: string): Promise[]> { return mixer.getFilters([{ kinds: [1], '#e': [eventId] }], { limit: 200, timeout: 2000 }); } -export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, getPublicFeed }; +/** Returns whether the pubkey is followed by a local user. */ +async function isLocallyFollowed(pubkey: string): Promise { + const [event] = await eventsDB.getFilters([{ kinds: [3], '#p': [pubkey], local: true }], { limit: 1 }); + return Boolean(event); +} + +export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, getPublicFeed, isLocallyFollowed };