mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 17:16:16 +08:00
1ceed6c145
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a Document Summary module, enabling live and cached document summaries with cloud revalidation. * Added a feature flag for enabling battery save mode. * Added explicit pause and resume controls for sync operations, accessible via UI events and programmatically. * **Improvements** * Enhanced sync and indexing logic to support pausing, resuming, and battery save mode, with improved job prioritization. * Updated navigation and preview components to use the new document summary service and improved priority handling. * Improved logging and state reporting for sync and indexing processes. * Refined backlink handling with reactive loading states and cloud revalidation. * Replaced backlink and link management to use a new dedicated document links service. * Enhanced workspace engine to conditionally enable battery save mode based on feature flags and workspace flavor. * **Bug Fixes** * Removed unnecessary debug console logs from various components for cleaner output. * **Refactor** * Replaced battery save mode methods with explicit pause/resume methods throughout the app and services. * Modularized and streamlined document summary and sync-related code for better maintainability. * Restructured backlink components to improve visibility handling and data fetching. * Simplified and improved document backlink data fetching with retry and loading state management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
182 lines
4.6 KiB
TypeScript
182 lines
4.6 KiB
TypeScript
import type { AvailableStorageImplementations } from '../impls';
|
|
import type {
|
|
AggregateResult,
|
|
BlobRecord,
|
|
DocClock,
|
|
DocClocks,
|
|
DocDiff,
|
|
DocRecord,
|
|
DocUpdate,
|
|
ListedBlobRecord,
|
|
Query,
|
|
SearchResult,
|
|
StorageType,
|
|
} from '../storage';
|
|
import type { AwarenessRecord } from '../storage/awareness';
|
|
import type { BlobSyncBlobState, BlobSyncState } from '../sync/blob';
|
|
import type { DocSyncDocState, DocSyncState } from '../sync/doc';
|
|
import type { IndexerDocSyncState, IndexerSyncState } from '../sync/indexer';
|
|
|
|
type StorageInitOptions = Values<{
|
|
[key in keyof AvailableStorageImplementations]: {
|
|
name: key;
|
|
opts: ConstructorParameters<AvailableStorageImplementations[key]>[0];
|
|
};
|
|
}>;
|
|
|
|
export interface StoreInitOptions {
|
|
local: { [key in StorageType]?: StorageInitOptions };
|
|
remotes: Record<string, { [key in StorageType]?: StorageInitOptions }>;
|
|
}
|
|
|
|
interface GroupedWorkerOps {
|
|
docStorage: {
|
|
getDoc: [string, DocRecord | null];
|
|
getDocDiff: [{ docId: string; state?: Uint8Array }, DocDiff | null];
|
|
pushDocUpdate: [{ update: DocUpdate; origin?: string }, DocClock];
|
|
getDocTimestamps: [Date | null, DocClocks];
|
|
getDocTimestamp: [string, DocClock | null];
|
|
deleteDoc: [string, void];
|
|
subscribeDocUpdate: [void, { update: DocRecord; origin?: string }];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
blobStorage: {
|
|
getBlob: [string, BlobRecord | null];
|
|
setBlob: [BlobRecord, void];
|
|
deleteBlob: [{ key: string; permanently: boolean }, void];
|
|
releaseBlobs: [void, void];
|
|
listBlobs: [void, ListedBlobRecord[]];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
awarenessStorage: {
|
|
update: [{ awareness: AwarenessRecord; origin?: string }, void];
|
|
subscribeUpdate: [
|
|
string,
|
|
(
|
|
| {
|
|
type: 'awareness-update';
|
|
awareness: AwarenessRecord;
|
|
origin?: string;
|
|
}
|
|
| { type: 'awareness-collect'; collectId: string }
|
|
),
|
|
];
|
|
collect: [{ collectId: string; awareness: AwarenessRecord }, void];
|
|
waitForConnected: [void, void];
|
|
};
|
|
|
|
docSync: {
|
|
state: [void, DocSyncState];
|
|
docState: [string, DocSyncDocState];
|
|
waitForSynced: [string | null, void];
|
|
addPriority: [{ docId: string; priority: number }, boolean];
|
|
resetSync: [void, void];
|
|
};
|
|
|
|
blobSync: {
|
|
state: [void, BlobSyncState];
|
|
blobState: [string, BlobSyncBlobState];
|
|
downloadBlob: [string, boolean];
|
|
uploadBlob: [{ blob: BlobRecord; force?: boolean }, true];
|
|
fullDownload: [string | null, void];
|
|
};
|
|
|
|
awarenessSync: {
|
|
update: [{ awareness: AwarenessRecord; origin?: string }, void];
|
|
subscribeUpdate: [
|
|
string,
|
|
(
|
|
| {
|
|
type: 'awareness-update';
|
|
awareness: AwarenessRecord;
|
|
origin?: string;
|
|
}
|
|
| { type: 'awareness-collect'; collectId: string }
|
|
),
|
|
];
|
|
collect: [{ collectId: string; awareness: AwarenessRecord }, void];
|
|
};
|
|
|
|
indexerSync: {
|
|
state: [void, IndexerSyncState];
|
|
docState: [string, IndexerDocSyncState];
|
|
addPriority: [{ docId: string; priority: number }, boolean];
|
|
waitForCompleted: [void, void];
|
|
waitForDocCompleted: [string, void];
|
|
search: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
options?: any;
|
|
},
|
|
SearchResult<any, any>,
|
|
];
|
|
aggregate: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
field: string;
|
|
options?: any;
|
|
},
|
|
AggregateResult<any, any>,
|
|
];
|
|
subscribeSearch: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
options?: any;
|
|
},
|
|
SearchResult<any, any>,
|
|
];
|
|
subscribeAggregate: [
|
|
{
|
|
table: string;
|
|
query: Query<any>;
|
|
field: string;
|
|
options?: any;
|
|
},
|
|
AggregateResult<any, any>,
|
|
];
|
|
};
|
|
sync: {
|
|
enableBatterySaveMode: [void, void];
|
|
disableBatterySaveMode: [void, void];
|
|
pauseSync: [void, void];
|
|
resumeSync: [void, void];
|
|
};
|
|
}
|
|
|
|
type Values<T> = T extends { [k in keyof T]: any } ? T[keyof T] : never;
|
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
|
|
x: infer I
|
|
) => void
|
|
? I
|
|
: never;
|
|
|
|
export type WorkerOps = UnionToIntersection<
|
|
Values<
|
|
Values<{
|
|
[k in keyof GroupedWorkerOps]: {
|
|
[k2 in keyof GroupedWorkerOps[k]]: k2 extends string
|
|
? Record<`${k}.${k2}`, GroupedWorkerOps[k][k2]>
|
|
: never;
|
|
};
|
|
}>
|
|
>
|
|
>;
|
|
|
|
export type WorkerManagerOps = {
|
|
open: [
|
|
{
|
|
port: MessagePort;
|
|
key: string;
|
|
closeKey: string;
|
|
options: StoreInitOptions;
|
|
},
|
|
string,
|
|
];
|
|
close: [string, void];
|
|
};
|