From bb90d74df55005f57c269688e41c463d03a7e1bf Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Sun, 10 Sep 2023 15:12:21 +0100 Subject: [PATCH] cursors: Fix cursor batching calculation The cursor batching algorithm was designed so that the overall channel message rate remains lower than an upper bound limit, and the algorithm expects the batching to multiply the batch interval by the number of members, not the number of members minus one as we're currently doing. Signed-off-by: Lewis Marshall --- src/Cursors.test.ts | 4 ++-- src/Cursors.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cursors.test.ts b/src/Cursors.test.ts index e51cb54a..e1e9c3fe 100644 --- a/src/Cursors.test.ts +++ b/src/Cursors.test.ts @@ -116,7 +116,7 @@ describe('Cursors', () => { vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2)); await cursors['onPresenceUpdate'](); expect(batching.shouldSend).toBeTruthy(); - expect(batching.batchTime).toEqual(100); + expect(batching.batchTime).toEqual(200); }); it('batchTime is updated when multiple people are present', async ({ @@ -126,7 +126,7 @@ describe('Cursors', () => { }) => { vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2)); await cursors['onPresenceUpdate'](); - expect(batching.batchTime).toEqual(100); + expect(batching.batchTime).toEqual(200); }); describe('pushCursorPosition', () => { diff --git a/src/Cursors.ts b/src/Cursors.ts index 34512b79..e3318bc2 100644 --- a/src/Cursors.ts +++ b/src/Cursors.ts @@ -76,7 +76,7 @@ export default class Cursors extends EventEmitter { const channel = this.getChannel(); const cursorsMembers = await channel.presence.get(); this.cursorBatching.setShouldSend(cursorsMembers.length > 1); - this.cursorBatching.setBatchTime((cursorsMembers.length - 1) * this.options.outboundBatchInterval); + this.cursorBatching.setBatchTime(cursorsMembers.length * this.options.outboundBatchInterval); } private isUnsubscribed() {