Skip to content

Commit

Permalink
fix(playground): remove database loading race condition (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zitrone44 authored Jan 18, 2025
1 parent 7543a19 commit 1a45513
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export class CollaborativeBackend implements Backend {
}

setMeta(databaseInformation: DatabaseInformation): Observable<void> {
//console.log("sm", databaseInformation)
this.metaMap.set("database", databaseInformation);
return of();
}

streamInputChanges(): Observable<ChangeEvent<QueryTab>> {
return new Observable<ChangeEvent<QueryTab>>((observer) => {
const handler = (event: Y.YMapEvent<QueryTab>) => {
//console.log("ic", event);
event.changes.keys.forEach((change, key) => {
let changeEvent: ChangeEvent<QueryTab>;
if (change.action === "add") {
Expand Down Expand Up @@ -126,6 +128,7 @@ export class CollaborativeBackend implements Backend {
emitInputChange(event: ChangeEvent<QueryTab>): Observable<void> {
return new Observable<void>((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)) {
Expand Down Expand Up @@ -179,6 +182,7 @@ export class CollaborativeBackend implements Backend {
streamMetaChanges(): Observable<any> {
return new Observable<{ key: string; value: any }>((observer) => {
const handler = (event: Y.YMapEvent<any>) => {
//console.log("mce", event)
event.changes.keys.forEach((change, key) => {
observer.next({
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,8 +58,8 @@ export class DatabasesEffects {
}
}),
catchError((error) => of(loadDatabasesFailure({ error })))
)
)
);
})
)
);

Expand Down

0 comments on commit 1a45513

Please sign in to comment.