mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 01:49:51 +08:00
feat(core): support better battery save mode (#13383)
<!-- 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 -->
This commit is contained in:
@@ -16,12 +16,12 @@ import { LinksRow } from '@affine/core/desktop/dialogs/doc-info/links-row';
|
||||
import { TimeRow } from '@affine/core/desktop/dialogs/doc-info/time-row';
|
||||
import type { DocCustomPropertyInfo } from '@affine/core/modules/db';
|
||||
import { DocDatabaseBacklinkInfo } from '@affine/core/modules/doc-info';
|
||||
import { DocsSearchService } from '@affine/core/modules/docs-search';
|
||||
import { DocLinksService } from '@affine/core/modules/doc-link';
|
||||
import { WorkspacePropertyService } from '@affine/core/modules/workspace-property';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { PlusIcon } from '@blocksuite/icons/rc';
|
||||
import { LiveData, useLiveData, useServices } from '@toeverything/infra';
|
||||
import { Suspense, useCallback, useMemo, useState } from 'react';
|
||||
import { useLiveData, useServices } from '@toeverything/infra';
|
||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import * as styles from './doc-info.css';
|
||||
|
||||
@@ -31,37 +31,16 @@ export const DocInfoSheet = ({
|
||||
docId: string;
|
||||
defaultOpenProperty?: DefaultOpenProperty;
|
||||
}) => {
|
||||
const { docsSearchService, workspacePropertyService } = useServices({
|
||||
DocsSearchService,
|
||||
const { workspacePropertyService, docLinksService } = useServices({
|
||||
WorkspacePropertyService,
|
||||
DocLinksService,
|
||||
});
|
||||
const t = useI18n();
|
||||
|
||||
const canEditPropertyInfo = useGuard('Workspace_Properties_Update');
|
||||
const canEditProperty = useGuard('Doc_Update', docId);
|
||||
const links = useLiveData(
|
||||
useMemo(
|
||||
() => LiveData.from(docsSearchService.watchRefsFrom(docId), null),
|
||||
[docId, docsSearchService]
|
||||
)
|
||||
);
|
||||
const backlinks = useLiveData(
|
||||
useMemo(() => {
|
||||
return LiveData.from(docsSearchService.watchRefsTo(docId), []).map(
|
||||
links => {
|
||||
const visitedDoc = new Set<string>();
|
||||
// for each doc, we only show the first block
|
||||
return links.filter(link => {
|
||||
if (visitedDoc.has(link.docId)) {
|
||||
return false;
|
||||
}
|
||||
visitedDoc.add(link.docId);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
);
|
||||
}, [docId, docsSearchService])
|
||||
);
|
||||
const links = useLiveData(docLinksService.links.links$);
|
||||
const backlinks = useLiveData(docLinksService.backlinks.backlinks$);
|
||||
|
||||
const [newPropertyId, setNewPropertyId] = useState<string | null>(null);
|
||||
|
||||
@@ -69,6 +48,10 @@ export const DocInfoSheet = ({
|
||||
setNewPropertyId(property.id);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
docLinksService.backlinks.revalidateFromCloud();
|
||||
}, [docLinksService.backlinks]);
|
||||
|
||||
const properties = useLiveData(workspacePropertyService.sortedProperties$);
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DocsSearchService } from '@affine/core/modules/docs-search';
|
||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
import { GlobalContextService } from '@affine/core/modules/global-context';
|
||||
import { NavigationPanelService } from '@affine/core/modules/navigation-panel';
|
||||
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import {
|
||||
LiveData,
|
||||
@@ -44,8 +45,10 @@ export const NavigationPanelDocNode = ({
|
||||
globalContextService,
|
||||
docDisplayMetaService,
|
||||
featureFlagService,
|
||||
workspaceService,
|
||||
} = useServices({
|
||||
DocsSearchService,
|
||||
WorkspaceService,
|
||||
DocsService,
|
||||
GlobalContextService,
|
||||
DocDisplayMetaService,
|
||||
@@ -95,9 +98,17 @@ export const NavigationPanelDocNode = ({
|
||||
|
||||
const [referencesLoading, setReferencesLoading] = useState(true);
|
||||
useLayoutEffect(() => {
|
||||
if (collapsed) {
|
||||
return;
|
||||
}
|
||||
const abortController = new AbortController();
|
||||
const undoSync = workspaceService.workspace.engine.doc.addPriority(
|
||||
docId,
|
||||
10
|
||||
);
|
||||
const undoIndexer = docsSearchService.indexer.addPriority(docId, 10);
|
||||
docsSearchService.indexer
|
||||
.waitForDocCompletedWithPriority(docId, 100, abortController.signal)
|
||||
.waitForDocCompleted(docId, abortController.signal)
|
||||
.then(() => {
|
||||
setReferencesLoading(false);
|
||||
})
|
||||
@@ -107,9 +118,11 @@ export const NavigationPanelDocNode = ({
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
undoSync();
|
||||
undoIndexer();
|
||||
abortController.abort(MANUALLY_STOP);
|
||||
};
|
||||
}, [docId, docsSearchService]);
|
||||
}, [docId, docsSearchService, workspaceService, collapsed]);
|
||||
|
||||
const workspaceDialogService = useService(WorkspaceDialogService);
|
||||
const option = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user