From fe5d5ce0752dffea1a37d20363431f53787d8e40 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 30 Jun 2023 15:55:28 +0100 Subject: [PATCH] Update tracking of collaboration events to only count unique users, and maybe fire in cloud envs --- packages/server/src/websockets/builder.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/server/src/websockets/builder.ts b/packages/server/src/websockets/builder.ts index 0f2c43e5ab..2524d9608b 100644 --- a/packages/server/src/websockets/builder.ts +++ b/packages/server/src/websockets/builder.ts @@ -18,13 +18,19 @@ export default class BuilderSocket extends BaseSocket { // Initial identification of selected app socket?.on(BuilderSocketEvent.SelectApp, async ({ appId }, callback) => { await this.joinRoom(socket, appId) - - // Reply with all users in current room const sessions = await this.getRoomSessions(appId) - callback({ users: sessions }) - // Track usage - await events.user.dataCollaboration(sessions.length) + // Track collaboration usage by unique users + let userIdMap: any = {} + sessions?.forEach(session => { + if (session._id) { + userIdMap[session._id] = true + } + }) + await events.user.dataCollaboration(Object.keys(userIdMap).length) + + // Reply with all current sessions + callback({ users: sessions }) }) }