Skip to content

Commit

Permalink
Respect cloud option disableEagerSync in regards to avoid pushing Y m…
Browse files Browse the repository at this point in the history
…essages to server
  • Loading branch information
David Fahlander committed Oct 10, 2024
1 parent 41332bf commit 0a10bd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion addons/dexie-cloud/src/WSObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DexieYProvider } from 'dexie';
import { getAwarenessLibrary, getDocAwareness } from './yjs/awareness';
import { encodeYMessage, decodeYMessage } from 'dexie-cloud-common';
import { UserLogin } from './dexie-cloud-client';
import { isEagerSyncDisabled } from './isEagerSyncDisabled';

const SERVER_PING_TIMEOUT = 20000;
const CLIENT_PING_INTERVAL = 30000;
Expand Down Expand Up @@ -366,7 +367,7 @@ export class WSConnection extends Subscription {
}
}
));
if (this.user.isLoggedIn && this.user.license?.status === 'ok') {
if (this.user.isLoggedIn && !isEagerSyncDisabled(this.db)) {
this.subscriptions.add(
createYClientUpdateObservable(this.db).subscribe(
this.db.messageProducer
Expand Down
5 changes: 3 additions & 2 deletions addons/dexie-cloud/src/yjs/createYHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { $Y } from './Y';
import { filter, firstValueFrom } from 'rxjs';
import { YDocumentOpen } from 'dexie-cloud-common';
import { DXCWebSocketStatus } from '../DXCWebSocketStatus';
import { isEagerSyncDisabled } from '../isEagerSyncDisabled';

type YDoc = import('yjs').Doc;

Expand All @@ -31,7 +32,7 @@ export function createYHandler(db: DexieCloudDB) {
// Send the update
const changedClients = added.concat(updated).concat(removed);
const user = db.cloud.currentUser.value;
if (origin !== 'server' && user.isLoggedIn && user.license?.status === 'ok') {
if (origin !== 'server' && user.isLoggedIn && !isEagerSyncDisabled(db)) {
const update = awap.encodeAwarenessUpdate(awareness!, changedClients);
db.messageProducer.next({
type: 'aware',
Expand Down Expand Up @@ -77,7 +78,7 @@ export function createYHandler(db: DexieCloudDB) {

// We are or got connected. Open the document on the server.
const user = db.cloud.currentUser.value;
if (wsStatus === "connected" && user.isLoggedIn && user.license?.status === 'ok') {
if (wsStatus === "connected" && user.isLoggedIn && !isEagerSyncDisabled(db)) {
++currentFlowId;
openDocumentOnServer(wsStatus).catch(error => {
console.warn(`Error catched in createYHandler.ts: ${error}`);
Expand Down

0 comments on commit 0a10bd9

Please sign in to comment.