fix(buffer): live counter
This commit is contained in:
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import withSuspense from '@/hocs/with-suspense';
|
||||
|
||||
import { getLiveVisitors } from '@openpanel/db';
|
||||
import { eventBuffer } from '@openpanel/db';
|
||||
|
||||
import type { LiveCounterProps } from './live-counter';
|
||||
import LiveCounter from './live-counter';
|
||||
|
||||
async function ServerLiveCounter(props: Omit<LiveCounterProps, 'data'>) {
|
||||
const count = await getLiveVisitors(props.projectId);
|
||||
const count = await eventBuffer.getActiveVisitorCount(props.projectId);
|
||||
return <LiveCounter data={count} {...props} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export default function useWS<T>(
|
||||
onMessage(event) {
|
||||
try {
|
||||
const data = getSuperJson<T>(event.data);
|
||||
if (data) {
|
||||
if (data !== null && data !== undefined) {
|
||||
debouncedOnMessage(data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user