Skip to content

Commit

Permalink
fix(core): dependency cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Jan 10, 2025
1 parent 2f49c06 commit adf1068
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion packages/frontend/core/src/modules/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { WorkspaceDBService } from './services/db';

export type { DocCustomPropertyInfo, DocProperties } from './schema';
export { WorkspaceDBService } from './services/db';
export { transformWorkspaceDBLocalToCloud } from './services/db';

export function configureWorkspaceDBModule(framework: Framework) {
framework
Expand Down
27 changes: 0 additions & 27 deletions packages/frontend/core/src/modules/db/services/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
createORMClient,
type DocStorage,
ObjectPool,
Service,
YjsDBAdapter,
Expand Down Expand Up @@ -100,29 +99,3 @@ export class WorkspaceDBService extends Service {
return docId.startsWith('db$') || docId.startsWith('userdata$');
}
}

export async function transformWorkspaceDBLocalToCloud(
localWorkspaceId: string,
cloudWorkspaceId: string,
localDocStorage: DocStorage,
cloudDocStorage: DocStorage,
accountId: string
) {
for (const tableName of Object.keys(AFFiNE_WORKSPACE_DB_SCHEMA)) {
const localDocName = `db$${localWorkspaceId}$${tableName}`;
const localDoc = await localDocStorage.doc.get(localDocName);
if (localDoc) {
const cloudDocName = `db$${cloudWorkspaceId}$${tableName}`;
await cloudDocStorage.doc.set(cloudDocName, localDoc);
}
}

for (const tableName of Object.keys(AFFiNE_WORKSPACE_USERDATA_DB_SCHEMA)) {
const localDocName = `userdata$__local__$${localWorkspaceId}$${tableName}`;
const localDoc = await localDocStorage.doc.get(localDocName);
if (localDoc) {
const cloudDocName = `userdata$${accountId}$${cloudWorkspaceId}$${tableName}`;
await cloudDocStorage.doc.set(cloudDocName, localDoc);
}
}
}
32 changes: 32 additions & 0 deletions packages/frontend/core/src/modules/db/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { DocStorage } from '@toeverything/infra';

import {
AFFiNE_WORKSPACE_DB_SCHEMA,
AFFiNE_WORKSPACE_USERDATA_DB_SCHEMA,
} from './schema';

export async function transformWorkspaceDBLocalToCloud(
localWorkspaceId: string,
cloudWorkspaceId: string,
localDocStorage: DocStorage,
cloudDocStorage: DocStorage,
accountId: string
) {
for (const tableName of Object.keys(AFFiNE_WORKSPACE_DB_SCHEMA)) {
const localDocName = `db$${localWorkspaceId}$${tableName}`;
const localDoc = await localDocStorage.doc.get(localDocName);
if (localDoc) {
const cloudDocName = `db$${cloudWorkspaceId}$${tableName}`;
await cloudDocStorage.doc.set(cloudDocName, localDoc);
}
}

for (const tableName of Object.keys(AFFiNE_WORKSPACE_USERDATA_DB_SCHEMA)) {
const localDocName = `userdata$__local__$${localWorkspaceId}$${tableName}`;
const localDoc = await localDocStorage.doc.get(localDocName);
if (localDoc) {
const cloudDocName = `userdata$${accountId}$${cloudWorkspaceId}$${tableName}`;
await cloudDocStorage.doc.set(cloudDocName, localDoc);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assertEquals } from '@blocksuite/affine/global/utils';
import { Service } from '@toeverything/infra';
import { applyUpdate } from 'yjs';

import { transformWorkspaceDBLocalToCloud } from '../../db';
import { transformWorkspaceDBLocalToCloud } from '../../db/utils';
import type { Workspace } from '../entities/workspace';
import type { WorkspaceMetadata } from '../metadata';
import type { WorkspaceDestroyService } from './destroy';
Expand Down

0 comments on commit adf1068

Please sign in to comment.