Skip to content

Commit 12467dd

Browse files
authored
Change cursors batch time formula on presence update (#333)
1 parent 50d8899 commit 12467dd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Cursors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('Cursors', () => {
116116
vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2));
117117
await cursors['onPresenceUpdate']();
118118
expect(batching.shouldSend).toBeTruthy();
119-
expect(batching.batchTime).toEqual(50);
119+
expect(batching.batchTime).toEqual(25);
120120
});
121121

122122
it<CursorsTestContext>('batchTime is updated when multiple people are present', async ({
@@ -126,7 +126,7 @@ describe('Cursors', () => {
126126
}) => {
127127
vi.spyOn(channel.presence, 'get').mockImplementation(createPresenceCount(2));
128128
await cursors['onPresenceUpdate']();
129-
expect(batching.batchTime).toEqual(50);
129+
expect(batching.batchTime).toEqual(25);
130130
});
131131

132132
describe('pushCursorPosition', () => {

src/Cursors.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export default class Cursors extends EventEmitter<CursorsEventMap> {
105105
const channel = this.getChannel();
106106
const cursorsMembers = await channel.presence.get();
107107
this.cursorBatching.setShouldSend(cursorsMembers.length > 1);
108-
this.cursorBatching.setBatchTime(cursorsMembers.length * this.options.outboundBatchInterval);
108+
/**
109+
* Since server-side batching is automically enabled for cursors channels, we can now adjust the client-side batching interval more granularly.
110+
* E.g. multiply the configured outboundBatchInterval by groups of 100 members instead of the total number of members.
111+
*/
112+
this.cursorBatching.setBatchTime(Math.ceil(cursorsMembers.length / 100) * this.options.outboundBatchInterval);
109113
}
110114

111115
private isUnsubscribed() {

0 commit comments

Comments
 (0)