Clean up subscribe a bit, add once

This commit is contained in:
Jon Staab
2024-05-17 13:57:49 -07:00
parent 42b3b8b5e7
commit 69b8bb3b54
3 changed files with 61 additions and 42 deletions
+10 -1
View File
@@ -2,7 +2,7 @@ import {Event} from 'nostr-tools'
import {matchFilter as nostrToolsMatchFilter} from 'nostr-tools'
import {prop, avg, hash, groupBy, randomId, uniq} from '@welshman/lib'
import type {HashedEvent, TrustedEvent} from './Events'
import {isReplaceableKind} from './Kinds'
import {isReplaceableKind, isPlainReplaceableKind} from './Kinds'
import {Address, getAddress} from './Address'
export const EPOCH = 1609459200
@@ -204,3 +204,12 @@ export const getFilterGenerality = (filter: Filter) => {
export const guessFilterDelta = (filters: Filter[], max = 60 * 60 * 24 * 7) =>
Math.round(max * Math.max(0.005, 1 - avg(filters.map(getFilterGenerality))))
// If a filter is specifying ids, we know how many results to expect
export const getFilterResultCardinality = (filter: Filter) => {
if (filter.ids) {
return filter.ids.length
}
return null
}