From 1a45513abf3b5530f0abed0cad9cb0ab74395d0f Mon Sep 17 00:00:00 2001 From: Jonas Kuche Date: Sat, 18 Jan 2025 23:05:26 +0100 Subject: [PATCH] fix(playground): remove database loading race condition (#1724) --- .../sql-playground/collab/collab.backend.ts | 4 ++++ .../db-control-panel/state/databases.effects.ts | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/fbs-core/web/src/app/page-components/sql-playground/collab/collab.backend.ts b/modules/fbs-core/web/src/app/page-components/sql-playground/collab/collab.backend.ts index 18562a354..cfe81267b 100644 --- a/modules/fbs-core/web/src/app/page-components/sql-playground/collab/collab.backend.ts +++ b/modules/fbs-core/web/src/app/page-components/sql-playground/collab/collab.backend.ts @@ -47,6 +47,7 @@ export class CollaborativeBackend implements Backend { } setMeta(databaseInformation: DatabaseInformation): Observable { + //console.log("sm", databaseInformation) this.metaMap.set("database", databaseInformation); return of(); } @@ -54,6 +55,7 @@ export class CollaborativeBackend implements Backend { streamInputChanges(): Observable> { return new Observable>((observer) => { const handler = (event: Y.YMapEvent) => { + //console.log("ic", event); event.changes.keys.forEach((change, key) => { let changeEvent: ChangeEvent; if (change.action === "add") { @@ -126,6 +128,7 @@ export class CollaborativeBackend implements Backend { emitInputChange(event: ChangeEvent): Observable { return new Observable((observer) => { this.yDoc.transact(() => { + //console.log("eic", event) if (event.event === "create" || event.event === "update") { const currentState = this.inputMap.get(event.payload.id); if (!queryTabEquals(currentState, event.payload)) { @@ -179,6 +182,7 @@ export class CollaborativeBackend implements Backend { streamMetaChanges(): Observable { return new Observable<{ key: string; value: any }>((observer) => { const handler = (event: Y.YMapEvent) => { + //console.log("mce", event) event.changes.keys.forEach((change, key) => { observer.next({ key, diff --git a/modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/state/databases.effects.ts b/modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/state/databases.effects.ts index 789624183..9cef28ca0 100644 --- a/modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/state/databases.effects.ts +++ b/modules/fbs-core/web/src/app/page-components/sql-playground/db-control-panel/state/databases.effects.ts @@ -40,8 +40,9 @@ export class DatabasesEffects { loadDatabases$ = createEffect(() => this.actions$.pipe( ofType(loadDatabases), - switchMap(() => - this.sqlPlaygroundService.getDatabases(this.token.id).pipe( + switchMap(() => { + if (!this.token) return; + return this.sqlPlaygroundService.getDatabases(this.token.id).pipe( switchMap((databases) => { if (databases.length == 0) { // create default database if none exists @@ -57,8 +58,8 @@ export class DatabasesEffects { } }), catchError((error) => of(loadDatabasesFailure({ error }))) - ) - ) + ); + }) ) );