mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(nbstore): add blob sync storage (#10752)
This commit is contained in:
@@ -3,6 +3,7 @@ import './array-to-spliced';
|
||||
import './dispose';
|
||||
import './iterator-helpers';
|
||||
import './promise-with-resolvers';
|
||||
import './set-union';
|
||||
|
||||
import { polyfillEventLoop } from './request-idle-callback';
|
||||
import { polyfillResizeObserver } from './resize-observer';
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import 'core-js/es/set/union.js';
|
||||
@@ -33,8 +33,8 @@ export const OverCapacityNotification = () => {
|
||||
useEffect(() => {
|
||||
const disposableOverCapacity =
|
||||
currentWorkspace.engine.blob.state$.subscribe(
|
||||
debounce(({ isStorageOverCapacity }: BlobSyncState) => {
|
||||
const isOver = isStorageOverCapacity;
|
||||
debounce(({ overCapacity }: BlobSyncState) => {
|
||||
const isOver = overCapacity;
|
||||
if (!isOver) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { Workspace } from '@affine/core/modules/workspace';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { universalId } from '@affine/nbstore';
|
||||
import track from '@affine/track';
|
||||
import { LiveData, useLiveData, useService } from '@toeverything/infra';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { useState } from 'react';
|
||||
|
||||
interface ExportPanelProps {
|
||||
workspace: Workspace;
|
||||
@@ -22,39 +22,18 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
||||
const desktopApi = useService(DesktopApiService);
|
||||
const isLocalWorkspace = workspace.flavour === 'local';
|
||||
|
||||
const docSyncState = useLiveData(
|
||||
useMemo(() => {
|
||||
return workspace
|
||||
? LiveData.from(workspace.engine.doc.state$, null).throttleTime(500)
|
||||
: null;
|
||||
}, [workspace])
|
||||
);
|
||||
|
||||
const blobSyncState = useLiveData(
|
||||
useMemo(() => {
|
||||
return workspace
|
||||
? LiveData.from(workspace.engine.blob.state$, null).throttleTime(500)
|
||||
: null;
|
||||
}, [workspace])
|
||||
);
|
||||
|
||||
const docSynced = !docSyncState?.syncing;
|
||||
const blobSynced =
|
||||
!blobSyncState || blobSyncState.synced === blobSyncState.total;
|
||||
const [fullSyncing, setFullSyncing] = useState(false);
|
||||
const [fullSynced, setFullSynced] = useState(false);
|
||||
|
||||
const shouldWaitForFullSync =
|
||||
isLocalWorkspace || !isOnline || (fullSynced && docSynced && blobSynced);
|
||||
const fullSyncing = fullSynced && (!docSynced || !blobSynced);
|
||||
const shouldWaitForFullSync = !isLocalWorkspace && isOnline && !fullSynced;
|
||||
|
||||
const fullSync = useAsyncCallback(async () => {
|
||||
// NOTE: doc full sync is always started by default
|
||||
// await workspace.engine.doc.waitForSynced();
|
||||
workspace.engine.blob.fullDownload().catch(() => {
|
||||
/* noop */
|
||||
});
|
||||
setFullSyncing(true);
|
||||
await workspace.engine.blob.fullDownload();
|
||||
await workspace.engine.doc.waitForSynced();
|
||||
setFullSynced(true);
|
||||
}, [workspace.engine.blob]);
|
||||
setFullSyncing(false);
|
||||
}, [workspace.engine.blob, workspace.engine.doc]);
|
||||
|
||||
const onExport = useAsyncCallback(async () => {
|
||||
if (saving) {
|
||||
@@ -86,7 +65,7 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
||||
}
|
||||
}, [desktopApi, saving, t, workspace]);
|
||||
|
||||
if (!shouldWaitForFullSync) {
|
||||
if (shouldWaitForFullSync) {
|
||||
return (
|
||||
<SettingRow name={t['Export']()} desc={t['Full Sync Description']()}>
|
||||
<Button
|
||||
|
||||
@@ -106,6 +106,7 @@ export class CMDKQuickSearchService extends Service {
|
||||
primaryMode: 'page',
|
||||
docProps,
|
||||
});
|
||||
|
||||
this.workbenchService.workbench.openDoc(newDoc.id);
|
||||
} else if (result.id === 'creation:create-edgeless') {
|
||||
const newDoc = this.docsService.createDoc({
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {
|
||||
import { CloudBlobStorage, StaticCloudDocStorage } from '@affine/nbstore/cloud';
|
||||
import {
|
||||
IndexedDBBlobStorage,
|
||||
IndexedDBBlobSyncStorage,
|
||||
IndexedDBDocStorage,
|
||||
IndexedDBDocSyncStorage,
|
||||
} from '@affine/nbstore/idb';
|
||||
@@ -22,6 +23,7 @@ import {
|
||||
} from '@affine/nbstore/idb/v1';
|
||||
import {
|
||||
SqliteBlobStorage,
|
||||
SqliteBlobSyncStorage,
|
||||
SqliteDocStorage,
|
||||
SqliteDocSyncStorage,
|
||||
} from '@affine/nbstore/sqlite';
|
||||
@@ -115,6 +117,10 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
|
||||
? SqliteDocSyncStorage
|
||||
: IndexedDBDocSyncStorage;
|
||||
BlobSyncStorageType =
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
|
||||
? SqliteBlobSyncStorage
|
||||
: IndexedDBBlobSyncStorage;
|
||||
|
||||
async deleteWorkspace(id: string): Promise<void> {
|
||||
await this.graphqlService.gql({
|
||||
@@ -439,6 +445,14 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
||||
id: workspaceId,
|
||||
},
|
||||
},
|
||||
blobSync: {
|
||||
name: this.BlobSyncStorageType.identifier,
|
||||
opts: {
|
||||
flavour: this.flavour,
|
||||
type: 'workspace',
|
||||
id: workspaceId,
|
||||
},
|
||||
},
|
||||
awareness: {
|
||||
name: 'BroadcastChannelAwarenessStorage',
|
||||
opts: {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@affine/nbstore';
|
||||
import {
|
||||
IndexedDBBlobStorage,
|
||||
IndexedDBBlobSyncStorage,
|
||||
IndexedDBDocStorage,
|
||||
IndexedDBDocSyncStorage,
|
||||
} from '@affine/nbstore/idb';
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
} from '@affine/nbstore/idb/v1';
|
||||
import {
|
||||
SqliteBlobStorage,
|
||||
SqliteBlobSyncStorage,
|
||||
SqliteDocStorage,
|
||||
SqliteDocSyncStorage,
|
||||
} from '@affine/nbstore/sqlite';
|
||||
@@ -101,6 +103,10 @@ class LocalWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
|
||||
? SqliteDocSyncStorage
|
||||
: IndexedDBDocSyncStorage;
|
||||
BlobSyncStorageType =
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS
|
||||
? SqliteBlobSyncStorage
|
||||
: IndexedDBBlobSyncStorage;
|
||||
|
||||
async deleteWorkspace(id: string): Promise<void> {
|
||||
setLocalWorkspaceIds(ids => ids.filter(x => x !== id));
|
||||
@@ -321,6 +327,14 @@ class LocalWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
||||
id: workspaceId,
|
||||
},
|
||||
},
|
||||
blobSync: {
|
||||
name: this.BlobSyncStorageType.identifier,
|
||||
opts: {
|
||||
flavour: this.flavour,
|
||||
type: 'workspace',
|
||||
id: workspaceId,
|
||||
},
|
||||
},
|
||||
docSync: {
|
||||
name: this.DocSyncStorageType.identifier,
|
||||
opts: {
|
||||
|
||||
@@ -63,5 +63,10 @@ export class WorkspaceEngine extends Entity<{
|
||||
this.doc.addPriority(rootDoc.guid, 100);
|
||||
this.doc.start();
|
||||
this.disposables.push(() => this.doc.stop());
|
||||
|
||||
// fully migrate blobs from v1 to v2, its won't do anything if v1 storage is not exist
|
||||
store.blobFrontend.fullDownload('v1').catch(() => {
|
||||
// should never reach here
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user