fix(server): wrong table used for userspace data (#7969)

This commit is contained in:
forehalo
2024-08-26 06:11:22 +00:00
parent 01c9d1758e
commit 14066965fa
2 changed files with 10 additions and 11 deletions

View File

@@ -37,6 +37,10 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
return false; return false;
} }
override async rollbackDoc() {
return;
}
override async getDoc(spaceId: string, docId: string) { override async getDoc(spaceId: string, docId: string) {
return this.getDocSnapshot(spaceId, docId); return this.getDocSnapshot(spaceId, docId);
} }
@@ -137,10 +141,10 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
protected async setDocSnapshot(snapshot: DocRecord) { protected async setDocSnapshot(snapshot: DocRecord) {
// we always get lock before writing to user snapshot table, // we always get lock before writing to user snapshot table,
// so a simple upsert without testing on updatedAt is safe // so a simple upsert without testing on updatedAt is safe
await this.db.snapshot.upsert({ await this.db.userSnapshot.upsert({
where: { where: {
id_workspaceId: { userId_id: {
workspaceId: snapshot.spaceId, userId: snapshot.spaceId,
id: snapshot.docId, id: snapshot.docId,
}, },
}, },
@@ -149,7 +153,7 @@ export class PgUserspaceDocStorageAdapter extends DocStorageAdapter {
updatedAt: new Date(snapshot.timestamp), updatedAt: new Date(snapshot.timestamp),
}, },
create: { create: {
workspaceId: snapshot.spaceId, userId: snapshot.spaceId,
id: snapshot.docId, id: snapshot.docId,
blob: Buffer.from(snapshot.bin), blob: Buffer.from(snapshot.bin),
createdAt: new Date(snapshot.timestamp), createdAt: new Date(snapshot.timestamp),

View File

@@ -11,6 +11,7 @@ import { Socket } from 'socket.io';
import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs'; import { diffUpdate, encodeStateVectorFromUpdate } from 'yjs';
import { import {
AlreadyInSpace,
CallTimer, CallTimer,
Config, Config,
DocNotFound, DocNotFound,
@@ -579,8 +580,7 @@ abstract class SyncSocketAdapter {
assertNotIn(spaceId: string, roomType: RoomType = 'sync') { assertNotIn(spaceId: string, roomType: RoomType = 'sync') {
if (this.client.rooms.has(this.room(spaceId, roomType))) { if (this.client.rooms.has(this.room(spaceId, roomType))) {
// TODO(@forehalo): use new AlreadyInSpace({ spaceId }) instead throw new AlreadyInSpace({ spaceId });
throw new NotInSpace({ spaceId });
} }
} }
@@ -621,11 +621,6 @@ class WorkspaceSyncAdapter extends SyncSocketAdapter {
super(SpaceType.Workspace, client, storage); super(SpaceType.Workspace, client, storage);
} }
// backward compatibility
override room(spaceId: string, roomType: RoomType = 'sync') {
return Room(spaceId, roomType);
}
override push(spaceId: string, docId: string, updates: Buffer[]) { override push(spaceId: string, docId: string, updates: Buffer[]) {
const id = new DocID(docId, spaceId); const id = new DocID(docId, spaceId);
return super.push(spaceId, id.guid, updates); return super.push(spaceId, id.guid, updates);