fix(buffer): live counter

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-11 21:38:26 +01:00
parent 848f475412
commit 3205ea0a31
6 changed files with 56 additions and 18 deletions

View File

@@ -6,8 +6,8 @@ import { getSuperJson } from '@openpanel/common';
import type { IServiceEvent, Notification } from '@openpanel/db';
import {
TABLE_NAMES,
eventBuffer,
getEvents,
getLiveVisitors,
getProfileByIdCached,
transformMinimalEvent,
} from '@openpanel/db';
@@ -82,20 +82,20 @@ export function wsVisitors(
if (channel === 'event:received') {
const event = getSuperJson<IServiceEvent>(message);
if (event?.projectId === params.projectId) {
getLiveVisitors(params.projectId).then((count) => {
eventBuffer.getActiveVisitorCount(params.projectId).then((count) => {
connection.socket.send(String(count));
});
}
}
};
const pmessage = (pattern: string, channel: string, message: string) => {
if (!message.startsWith('live:visitors:')) {
if (!message.startsWith('live:visitor:')) {
return null;
}
const [projectId] = getLiveEventInfo(message);
if (projectId && projectId === params.projectId) {
getLiveVisitors(params.projectId).then((count) => {
eventBuffer.getActiveVisitorCount(params.projectId).then((count) => {
connection.socket.send(String(count));
});
}