Skip to content

Commit 1406696

Browse files
committed
fix(server): wrong table used for userspace data (#7969)
1 parent 01c9d17 commit 1406696

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

packages/backend/server/src/core/doc/adapters/userspace.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
3737
return false;
3838
}
3939

40+
override async rollbackDoc() {
41+
return;
42+
}
43+
4044
override async getDoc(spaceId: string, docId: string) {
4145
return this.getDocSnapshot(spaceId, docId);
4246
}
@@ -137,10 +141,10 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
137141
protected async setDocSnapshot(snapshot: DocRecord) {
138142
// we always get lock before writing to user snapshot table,
139143
// so a simple upsert without testing on updatedAt is safe
140-
await this.db.snapshot.upsert({
144+
await this.db.userSnapshot.upsert({
141145
where: {
142-
id_workspaceId: {
143-
workspaceId: snapshot.spaceId,
146+
userId_id: {
147+
userId: snapshot.spaceId,
144148
id: snapshot.docId,
145149
},
146150
},
@@ -149,7 +153,7 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
149153
updatedAt: new Date(snapshot.timestamp),
150154
},
151155
create: {
152-
workspaceId: snapshot.spaceId,
156+
userId: snapshot.spaceId,
153157
id: snapshot.docId,
154158
blob: Buffer.from(snapshot.bin),
155159
createdAt: new Date(snapshot.timestamp),

packages/backend/server/src/core/sync/gateway.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Socket } from 'socket.io';
1111
import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs';
1212

1313
import {
14+
AlreadyInSpace,
1415
CallTimer,
1516
Config,
1617
DocNotFound,
@@ -579,8 +580,7 @@ abstract class SyncSocketAdapter {
579580

580581
assertNotIn(spaceId: string, roomType: RoomType = 'sync') {
581582
if (this.client.rooms.has(this.room(spaceId, roomType))) {
582-
// TODO(@forehalo): use new AlreadyInSpace({ spaceId }) instead
583-
throw new NotInSpace({ spaceId });
583+
throw new AlreadyInSpace({ spaceId });
584584
}
585585
}
586586

@@ -621,11 +621,6 @@ class WorkspaceSyncAdapter extends SyncSocketAdapter {
621621
super(SpaceType.Workspace, client, storage);
622622
}
623623

624-
// backward compatibility
625-
override room(spaceId: string, roomType: RoomType = 'sync') {
626-
return Room(spaceId, roomType);
627-
}
628-
629624
override push(spaceId: string, docId: string, updates: Buffer[]) {
630625
const id = new DocID(docId, spaceId);
631626
return super.push(spaceId, id.guid, updates);

0 commit comments

Comments
 (0)