Skip to content

Commit 466db06

Browse files
alecgeatchesalecgeatchesingeniumedchriszaratet-hamano
authored
RTC: Increase polling intervals, increase polling on primary room only (#76704)
* Bump polling intervals up by 4x * Reset `hasCollaborators` flag on awareness check * Use the first registered room as the primaryRoom, and only pay attention to awareness results from that entity to avoid poll increases from shared entities like categores * Simplify primaryRoom and enforceConnectionLimit * Fix the collaboration utility setup for collaboration tests --------- Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
1 parent c24aeab commit 466db06

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

packages/editor/src/components/sync-connection-error-modal/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ const { BlockCanvasCover } = unlock( privateApis );
3535
const { retrySyncConnection } = unlock( coreDataPrivateApis );
3636

3737
// Debounce time for initial disconnected status to allow connection to establish.
38-
const INITIAL_DISCONNECTED_DEBOUNCE_MS = 5000;
38+
const INITIAL_DISCONNECTED_DEBOUNCE_MS = 20000;
3939

4040
// Debounce time for showing the disconnect dialog after the intial connection,
4141
// allowing brief network interruptions to resolve.
42-
const DISCONNECTED_DEBOUNCE_MS = 2000;
42+
const DISCONNECTED_DEBOUNCE_MS = 8000;
4343

4444
export interface SyncConnectionErrorModalProps {
4545
description: string; // Modal description.

packages/sync/src/providers/http-polling/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export const MAX_UPDATE_SIZE_IN_BYTES = 1 * 1024 * 1024; // 1 MB
99

1010
export const POLLING_INTERVAL_IN_MS = applyFilters(
1111
'sync.pollingManager.pollingInterval',
12-
1000 // 1 second or 1000 milliseconds
12+
4000 // 4 seconds
1313
) as number;
1414

1515
export const POLLING_INTERVAL_WITH_COLLABORATORS_IN_MS = applyFilters(
1616
'sync.pollingManager.pollingIntervalWithCollaborators',
17-
250 // 250 milliseconds
17+
1000 // 1 second
1818
) as number;
1919

2020
// Must be less than the server-side AWARENESS_TIMEOUT (30 s) to avoid

packages/sync/src/providers/http-polling/polling-manager.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ interface RoomState {
6666
clientId: number;
6767
createCompactionUpdate: () => SyncUpdate;
6868
endCursor: number;
69-
enforceConnectionLimit: boolean;
69+
isPrimaryRoom: boolean;
7070
localAwarenessState: LocalAwarenessState;
7171
log: LogFunction;
7272
onStatusChange: ( status: ConnectionStatus ) => void;
@@ -267,12 +267,12 @@ function checkConnectionLimit(
267267
awareness: AwarenessState,
268268
roomState: RoomState
269269
): boolean {
270-
if ( ! roomState.enforceConnectionLimit ) {
270+
if ( ! roomState.isPrimaryRoom || hasCheckedConnectionLimit ) {
271271
return false;
272272
}
273273

274274
// Limits are only enforced on the initial connection.
275-
roomState.enforceConnectionLimit = false;
275+
hasCheckedConnectionLimit = true;
276276

277277
const maxClientsPerRoom = applyFilters(
278278
'sync.pollingProvider.maxClientsPerRoom',
@@ -300,6 +300,7 @@ function checkConnectionLimit(
300300
}
301301

302302
let areListenersRegistered = false;
303+
let hasCheckedConnectionLimit = false;
303304
let hasCollaborators = false;
304305
let isActiveBrowser = 'visible' === document.visibilityState;
305306
let isPolling = false;
@@ -418,6 +419,9 @@ function poll(): void {
418419
state.onStatusChange( { status: 'connected' } );
419420
} );
420421

422+
// Reset before checking each room
423+
hasCollaborators = false;
424+
421425
rooms.forEach( ( room ) => {
422426
if ( ! roomStates.has( room.room ) ) {
423427
return;
@@ -442,9 +446,14 @@ function poll(): void {
442446
// Process awareness update.
443447
roomState.processAwarenessUpdate( room.awareness );
444448

445-
// If there is another collaborator, resume the queue for the next poll
446-
// and increase polling frequency.
447-
if ( Object.keys( room.awareness ).length > 1 ) {
449+
// If there is another collaborator on the primary entity,
450+
// resume the queue for the next poll and increase polling
451+
// frequency. We only check the primary room to avoid false
452+
// positives from shared collection rooms (e.g. taxonomy/category).
453+
if (
454+
roomState.isPrimaryRoom &&
455+
Object.keys( room.awareness ).length > 1
456+
) {
448457
hasCollaborators = true;
449458
roomState.updateQueue.resume();
450459
}
@@ -576,7 +585,7 @@ function registerRoom( {
576585
* How might this approach be improved? We could develop some way to annotate
577586
* entity loading so that the consumer can indicate which entity is primary.
578587
*/
579-
const enforceConnectionLimit = 0 === roomStates.size;
588+
const isPrimaryRoom = 0 === roomStates.size;
580589

581590
function onAwarenessUpdate(): void {
582591
roomState.localAwarenessState = awareness.getLocalState() ?? {};
@@ -628,7 +637,7 @@ function registerRoom( {
628637
SyncUpdateType.COMPACTION
629638
),
630639
endCursor: 0,
631-
enforceConnectionLimit,
640+
isPrimaryRoom,
632641
localAwarenessState: awareness.getLocalState() ?? {},
633642
log,
634643
onStatusChange,
@@ -685,6 +694,7 @@ function unregisterRoom( room: string ): void {
685694
handleVisibilityChange
686695
);
687696
areListenersRegistered = false;
697+
hasCheckedConnectionLimit = false;
688698
}
689699
}
690700

test/e2e/specs/editor/collaboration/fixtures/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export { expect } from '@wordpress/e2e-test-utils-playwright';
77
/**
88
* Internal dependencies
99
*/
10-
import CollaborationUtils, { SECOND_USER } from './collaboration-utils';
10+
import CollaborationUtils, {
11+
SECOND_USER,
12+
setCollaboration,
13+
} from './collaboration-utils';
1114

1215
type Fixtures = {
1316
collaborationUtils: CollaborationUtils;
@@ -27,7 +30,9 @@ export const test = base.extend< Fixtures >( {
2730
// Clean up any leftover users from previous runs before creating.
2831
await requestUtils.deleteAllUsers();
2932
await requestUtils.createUser( SECOND_USER );
33+
await setCollaboration( requestUtils, true );
3034
await use( utils );
3135
await utils.teardown();
36+
await setCollaboration( requestUtils, false );
3237
},
3338
} );

0 commit comments

Comments
 (0)