Skip to content

Commit

Permalink
fix: adjust relay instance destruction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Jun 22, 2024
1 parent 5097644 commit 13b5983
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 25 deletions.
4 changes: 0 additions & 4 deletions packages/core/__test__/nostr-relay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,6 @@ describe('NostrRelay', () => {

describe('destroy', () => {
it('should destroy successfully', async () => {
const mockSubscriptionServiceRemoveAllClients = jest
.spyOn(nostrRelay['subscriptionService'], 'removeAllClients')
.mockImplementation();
const mockLazyCacheClear = jest
.spyOn(nostrRelay['eventHandlingLazyCache']!, 'clear')
.mockImplementation();
Expand All @@ -455,7 +452,6 @@ describe('NostrRelay', () => {
await nostrRelay.destroy();

expect(nostrRelay['clientContexts'].size).toBe(0);
expect(mockSubscriptionServiceRemoveAllClients).toHaveBeenCalled();
expect(mockLazyCacheClear).toHaveBeenCalled();
expect(mockEventServiceDestroy).toHaveBeenCalled();
});
Expand Down
4 changes: 0 additions & 4 deletions packages/core/__test__/services/event.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,10 @@ describe('eventService', () => {
const mockFindLazyCacheClear = jest
.spyOn(eventServiceWithCache['findLazyCache']!, 'clear')
.mockImplementation();
const mockEventRepositoryDestroy = jest
.spyOn(eventRepository, 'destroy')
.mockImplementation();

await eventServiceWithCache.destroy();

expect(mockFindLazyCacheClear).toHaveBeenCalled();
expect(mockEventRepositoryDestroy).toHaveBeenCalled();
});
});
});
11 changes: 0 additions & 11 deletions packages/core/__test__/services/subscription.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,4 @@ describe('SubscriptionService', () => {
expect(spyLoggerError).toHaveBeenCalled();
});
});

describe('removeAllClients', () => {
it('should remove all clients', () => {
subscriptionService.subscribe(ctx, 'subscriptionId', [{}]);
expect(clientsMap.size).toEqual(1);

subscriptionService.removeAllClients();

expect(clientsMap.size).toEqual(0);
});
});
});
1 change: 0 additions & 1 deletion packages/core/src/nostr-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ export class NostrRelay {
*/
async destroy(): Promise<void> {
this.clientContexts.clear();
this.subscriptionService.removeAllClients();
this.eventHandlingLazyCache?.clear();
await this.eventService.destroy();
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,5 @@ export class EventService {

async destroy(): Promise<void> {
this.findLazyCache?.clear();
await this.eventRepository.destroy();
}
}
4 changes: 0 additions & 4 deletions packages/core/src/services/subscription.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export class SubscriptionService {
return ctx.subscriptions.delete(subscriptionId);
}

removeAllClients(): void {
this.clientsMap.clear();
}

async broadcast(event: Event): Promise<void> {
try {
for (const ctx of this.clientsMap.values()) {
Expand Down

0 comments on commit 13b5983

Please sign in to comment.