fix: disable move db by default (#3105)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Peng Xiao 2023-07-09 11:37:39 +08:00 committed by GitHub
parent bc85ad5b65
commit 33644a68b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 18 deletions

View File

@ -17,7 +17,7 @@ test('check workspace has a DB file', async ({ appInfo, workspace }) => {
expect(await fs.exists(dbPath)).toBe(true); expect(await fs.exists(dbPath)).toBe(true);
}); });
test('move workspace db file', async ({ page, appInfo, workspace }) => { test.skip('move workspace db file', async ({ page, appInfo, workspace }) => {
const w = await workspace.current(); const w = await workspace.current();
await page.getByTestId('slider-bar-workspace-setting-button').click(); await page.getByTestId('slider-bar-workspace-setting-button').click();
await expect(page.getByTestId('setting-modal')).toBeVisible(); await expect(page.getByTestId('setting-modal')).toBeVisible();

View File

@ -115,19 +115,43 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
} }
setupListener(docId?: string) { setupListener(docId?: string) {
logger.debug(
'SecondaryWorkspaceSQLiteDB:setupListener',
this.workspaceId,
docId
);
const doc = this.getDoc(docId); const doc = this.getDoc(docId);
if (!doc) { const upstreamDoc = this.upstream.getDoc(docId);
if (!doc || !upstreamDoc) {
logger.warn(
'[SecondaryWorkspaceSQLiteDB] setupListener: doc not found',
docId
);
return; return;
} }
const onUpstreamUpdate = (update: Uint8Array, origin: YOrigin) => { const onUpstreamUpdate = (update: Uint8Array, origin: YOrigin) => {
if (origin === 'renderer') { logger.debug(
'SecondaryWorkspaceSQLiteDB:onUpstreamUpdate',
origin,
this.workspaceId,
docId,
update.length
);
if (origin === 'renderer' || origin === 'self') {
// update to upstream yDoc should be replicated to self yDoc // update to upstream yDoc should be replicated to self yDoc
this.applyUpdate(update, 'upstream', docId); this.applyUpdate(update, 'upstream', docId);
} }
}; };
const onSelfUpdate = async (update: Uint8Array, origin: YOrigin) => { const onSelfUpdate = async (update: Uint8Array, origin: YOrigin) => {
logger.debug(
'SecondaryWorkspaceSQLiteDB:onSelfUpdate',
origin,
this.workspaceId,
docId,
update.length
);
// for self update from upstream, we need to push it to external DB // for self update from upstream, we need to push it to external DB
if (origin === 'upstream') { if (origin === 'upstream') {
await this.addUpdateToUpdateQueue({ await this.addUpdateToUpdateQueue({
@ -147,15 +171,19 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
}); });
}; };
doc.subdocs.forEach(subdoc => {
this.setupListener(subdoc.guid);
});
// listen to upstream update // listen to upstream update
this.upstream.yDoc.on('update', onUpstreamUpdate); this.upstream.yDoc.on('update', onUpstreamUpdate);
this.yDoc.on('update', onSelfUpdate); doc.on('update', onSelfUpdate);
this.yDoc.on('subdocs', onSubdocs); doc.on('subdocs', onSubdocs);
this.unsubscribers.add(() => { this.unsubscribers.add(() => {
this.upstream.yDoc.off('update', onUpstreamUpdate); this.upstream.yDoc.off('update', onUpstreamUpdate);
this.yDoc.off('update', onSelfUpdate); doc.off('update', onSelfUpdate);
this.yDoc.off('subdocs', onSubdocs); doc.off('subdocs', onSubdocs);
}); });
} }
@ -188,7 +216,10 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
if (doc) { if (doc) {
Y.applyUpdate(this.yDoc, data, origin); Y.applyUpdate(this.yDoc, data, origin);
} else { } else {
logger.warn('applyUpdate: doc not found', docId); logger.warn(
'[SecondaryWorkspaceSQLiteDB] applyUpdate: doc not found',
docId
);
} }
}; };

View File

@ -151,7 +151,7 @@ export class WorkspaceSQLiteDB extends BaseSQLiteAdapter {
if (doc) { if (doc) {
Y.applyUpdate(doc, data, origin); Y.applyUpdate(doc, data, origin);
} else { } else {
logger.warn('applyUpdate: doc not found', docId); logger.warn('[WorkspaceSQLiteDB] applyUpdate: doc not found', docId);
} }
}; };

View File

@ -227,7 +227,6 @@ export async function loadDBFile(): Promise<LoadDBFileResult> {
await storeWorkspaceMeta(workspaceId, { await storeWorkspaceMeta(workspaceId, {
id: workspaceId, id: workspaceId,
mainDBPath: internalFilePath, mainDBPath: internalFilePath,
secondaryDBPath: filePath,
}); });
return { workspaceId }; return { workspaceId };

View File

@ -28,6 +28,7 @@ const buildPreset = {
enableNewSettingModal: true, enableNewSettingModal: true,
enableNewSettingUnstableApi: false, enableNewSettingUnstableApi: false,
enableSQLiteProvider: true, enableSQLiteProvider: true,
enableMoveDatabase: false,
enableNotificationCenter: false, enableNotificationCenter: false,
enableCloud: false, enableCloud: false,
}, },
@ -44,6 +45,7 @@ const buildPreset = {
enableNewSettingModal: true, enableNewSettingModal: true,
enableNewSettingUnstableApi: false, enableNewSettingUnstableApi: false,
enableSQLiteProvider: true, enableSQLiteProvider: true,
enableMoveDatabase: false,
enableNotificationCenter: true, enableNotificationCenter: true,
enableCloud: false, enableCloud: false,
}, },
@ -90,6 +92,9 @@ const environmentPreset = {
enableCloud: process.env.ENABLE_CLOUD enableCloud: process.env.ENABLE_CLOUD
? process.env.ENABLE_CLOUD === 'true' ? process.env.ENABLE_CLOUD === 'true'
: currentBuildPreset.enableCloud, : currentBuildPreset.enableCloud,
enableMoveDatabase: process.env.ENABLE_MOVE_DATABASE
? process.env.ENABLE_MOVE_DATABASE === 'true'
: currentBuildPreset.enableMoveDatabase,
}; };
/** /**

View File

@ -9,7 +9,7 @@ import type {
} from '@affine/env/workspace'; } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name'; import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import type { FC } from 'react'; import { type FC, useMemo } from 'react';
import { useWorkspace } from '../../../hooks/use-workspace'; import { useWorkspace } from '../../../hooks/use-workspace';
import { DeleteLeaveWorkspace } from './delete-leave-workspace'; import { DeleteLeaveWorkspace } from './delete-leave-workspace';
@ -40,6 +40,21 @@ export const WorkspaceSettingDetail: FC<WorkspaceSettingDetailProps> = ({
const workspace = useWorkspace(workspaceId); const workspace = useWorkspace(workspaceId);
const [name] = useBlockSuiteWorkspaceName(workspace.blockSuiteWorkspace); const [name] = useBlockSuiteWorkspaceName(workspace.blockSuiteWorkspace);
const storageAndExportSetting = useMemo(() => {
if (environment.isDesktop) {
return (
<SettingWrapper title={t['Storage and Export']()}>
{runtimeConfig.enableMoveDatabase ? (
<StoragePanel workspace={workspace} />
) : null}
<ExportPanel workspace={workspace} />
</SettingWrapper>
);
} else {
return null;
}
}, [t, workspace]);
return ( return (
<> <>
<SettingHeader <SettingHeader
@ -64,13 +79,7 @@ export const WorkspaceSettingDetail: FC<WorkspaceSettingDetailProps> = ({
{...props} {...props}
/> />
</SettingWrapper> </SettingWrapper>
{environment.isDesktop ? ( {storageAndExportSetting}
<SettingWrapper title={t['Storage and Export']()}>
<StoragePanel workspace={workspace} />
<ExportPanel workspace={workspace} />
</SettingWrapper>
) : null}
<SettingWrapper> <SettingWrapper>
<DeleteLeaveWorkspace <DeleteLeaveWorkspace
workspace={workspace} workspace={workspace}

View File

@ -69,6 +69,7 @@ export const buildFlagsSchema = z.object({
enableSQLiteProvider: z.boolean(), enableSQLiteProvider: z.boolean(),
enableNotificationCenter: z.boolean(), enableNotificationCenter: z.boolean(),
enableCloud: z.boolean(), enableCloud: z.boolean(),
enableMoveDatabase: z.boolean(),
}); });
export const blockSuiteFeatureFlags = z.object({ export const blockSuiteFeatureFlags = z.object({