From 6b20104327e4b7f4127b89bc8fa60263dee553be Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 3 May 2024 13:26:26 -0500 Subject: [PATCH] filter: use getFilterLimit from nostr-tools --- src/filter.ts | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/filter.ts b/src/filter.ts index 59b0298..fd698c4 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,9 +1,8 @@ import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify'; import stringifyStable from 'fast-stable-stringify'; +import { getFilterLimit } from 'nostr-tools'; import { z } from 'zod'; -import { isReplaceableKind } from '@/kinds.ts'; - /** Microfilter to get one specific event by ID. */ type IdMicrofilter = { ids: [NostrEvent['id']] }; /** Microfilter to get an author. */ @@ -50,22 +49,6 @@ function isMicrofilter(filter: NostrFilter): filter is MicroFilter { return microFilterSchema.safeParse(filter).success; } -/** Calculate the intrinsic limit of a filter. */ -function getFilterLimit(filter: NostrFilter): number { - if (filter.ids && !filter.ids.length) return 0; - if (filter.kinds && !filter.kinds.length) return 0; - if (filter.authors && !filter.authors.length) return 0; - - return Math.min( - Math.max(0, filter.limit ?? Infinity), - filter.ids?.length ?? Infinity, - filter.authors?.length && - filter.kinds?.every((kind) => isReplaceableKind(kind)) - ? filter.authors.length * filter.kinds.length - : Infinity, - ); -} - /** Returns true if the filter could potentially return any stored events at all. */ function canFilter(filter: NostrFilter): boolean { return getFilterLimit(filter) > 0;