Fix sync with dumb relays

This commit is contained in:
Jon Staab
2024-10-17 10:41:30 -07:00
parent c0b66557c4
commit eec1552f5d
2 changed files with 10 additions and 4 deletions
+8
View File
@@ -27,6 +27,14 @@ export const inc = (x: number | Nil) => (x || 0) + 1
export const dec = (x: number | Nil) => (x || 0) - 1 export const dec = (x: number | Nil) => (x || 0) - 1
export const lt = (x: number | Nil, y: number | Nil) => (x || 0) < (y || 0)
export const lte = (x: number | Nil, y: number | Nil) => (x || 0) <= (y || 0)
export const gt = (x: number | Nil, y: number | Nil) => (x || 0) > (y || 0)
export const gte = (x: number | Nil, y: number | Nil) => (x || 0) >= (y || 0)
export const max = (xs: number[]) => xs.reduce((a, b) => Math.max(a, b), 0) export const max = (xs: number[]) => xs.reduce((a, b) => Math.max(a, b), 0)
export const min = (xs: number[]) => xs.reduce((a, b) => Math.min(a, b), 0) export const min = (xs: number[]) => xs.reduce((a, b) => Math.min(a, b), 0)
+2 -4
View File
@@ -1,4 +1,4 @@
import {ctx, groupBy, now, pushToMapKey, inc, flatten, chunk} from '@welshman/lib' import {ctx, assoc, lt, groupBy, now, pushToMapKey, inc, flatten, chunk} from '@welshman/lib'
import type {SignedEvent, TrustedEvent, Filter} from '@welshman/util' import type {SignedEvent, TrustedEvent, Filter} from '@welshman/util'
import {subscribe} from './Subscribe' import {subscribe} from './Subscribe'
import {publish} from './Publish' import {publish} from './Publish'
@@ -168,9 +168,7 @@ export const pullWithoutNegentropy = async ({relays, filters, onEvent}: PullWith
await new Promise<void>(resolve => { await new Promise<void>(resolve => {
subscribe({ subscribe({
relays, relays,
filters: filters filters: filters.filter(f => lt(f.since, until)).map(assoc('until', until)),
.filter(filter => !filter.since || filter.since > until)
.map(filter => ({...filter, until})),
closeOnEose: true, closeOnEose: true,
onClose: () => { onClose: () => {
done = !anyResults done = !anyResults