Skip to content

Commit 442f571

Browse files
refactor: remove duplicate expiration filter in subscription replay
1 parent 15273e0 commit 442f571

2 files changed

Lines changed: 2 additions & 23 deletions

File tree

src/handlers/subscribe-message-handler.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
5959
const sendEOSE = () =>
6060
this.webSocket.emit(WebSocketAdapterEvent.Message, createEndOfStoredEventsNoticeMessage(subscriptionId))
6161
const isSubscribedToEvent = SubscribeMessageHandler.isClientSubscribedToEvent(filters)
62-
const isNotExpired = (event: Event) => {
62+
const isTagUnexpired = (event: Event) => {
6363
if (isExpiredEvent(event)) {
6464
return false
6565
}
@@ -74,9 +74,8 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
7474
await pipeline(
7575
findEvents,
7676
streamFilter(propSatisfies(isNil, 'deleted_at')),
77-
streamFilter(SubscribeMessageHandler.isNotExpired),
7877
streamMap(toNostrEvent),
79-
streamFilter(isNotExpired),
78+
streamFilter(isTagUnexpired),
8079
streamFilter(isSubscribedToEvent),
8180
streamEach(sendEvent),
8281
streamEnd(sendEOSE),
@@ -96,11 +95,6 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
9695
return anyPass(map(isEventMatchingFilter)(filters))
9796
}
9897

99-
private static isNotExpired(event: { expires_at?: number }): boolean {
100-
const now = Math.floor(Date.now() / 1000)
101-
return typeof event.expires_at !== 'number' || event.expires_at > now
102-
}
103-
10498
private canSubscribe(subscriptionId: SubscriptionId, filters: SubscriptionFilter[]): string | undefined {
10599
const subscriptions = this.webSocket.getSubscriptions()
106100
const existingSubscription = subscriptions.get(subscriptionId)

test/unit/handlers/subscribe-message-handler.spec.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,6 @@ describe('SubscribeMessageHandler', () => {
210210
expect(webSocketOnMessageStub).to.have.been.calledWithExactly(['EOSE', subscriptionId])
211211
})
212212

213-
it('does not send expired stored events', async () => {
214-
isClientSubscribedToEventStub.returns(always(true))
215-
216-
const promise = (handler as any).fetchAndSend(subscriptionId, filters)
217-
218-
stream.write(toDbEvent(event, { expires_at: Math.floor(Date.now() / 1000) - 1 }))
219-
stream.end()
220-
221-
await promise
222-
223-
expect(webSocketOnMessageStub).to.have.been.calledOnceWithExactly(
224-
['EOSE', subscriptionId],
225-
)
226-
})
227-
228213
it('sends EOSE', async () => {
229214
const promise = (handler as any).fetchAndSend(subscriptionId, filters)
230215

0 commit comments

Comments
 (0)