Skip to content

Commit bd48016

Browse files
authored
optimise redis operations (#111)
1 parent c14e541 commit bd48016

2 files changed

Lines changed: 1 addition & 23 deletions

File tree

apps/api/src/controllers/live.controller.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ import {
88
transformMinimalEvent,
99
} from '@openpanel/db';
1010
import { setSuperJson } from '@openpanel/json';
11-
import {
12-
psubscribeToPublishedEvent,
13-
subscribeToPublishedEvent,
14-
} from '@openpanel/redis';
11+
import { subscribeToPublishedEvent } from '@openpanel/redis';
1512
import { getProjectAccess } from '@openpanel/trpc';
1613
import { getOrganizationAccess } from '@openpanel/trpc/src/access';
1714

18-
export function getLiveEventInfo(key: string) {
19-
return key.split(':').slice(2) as [string, string];
20-
}
21-
2215
export function wsVisitors(
2316
socket: WebSocket,
2417
req: FastifyRequest<{
@@ -36,21 +29,8 @@ export function wsVisitors(
3629
}
3730
});
3831

39-
const punsubscribe = psubscribeToPublishedEvent(
40-
'__keyevent@0__:expired',
41-
(key) => {
42-
const [projectId] = getLiveEventInfo(key);
43-
if (projectId && projectId === params.projectId) {
44-
eventBuffer.getActiveVisitorCount(params.projectId).then((count) => {
45-
socket.send(String(count));
46-
});
47-
}
48-
},
49-
);
50-
5132
socket.on('close', () => {
5233
unsubscribe();
53-
punsubscribe();
5434
});
5535
}
5636

packages/db/src/buffers/event-buffer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ return added
278278
if (!_multi) {
279279
await multi.exec();
280280
}
281-
282-
await publishEvent('events', 'received', transformEvent(event));
283281
} catch (error) {
284282
this.logger.error('Failed to add event to Redis buffer', { error });
285283
}

0 commit comments

Comments
 (0)