perf: reduce unused provider connection (#3090)

(cherry picked from commit 3294043180)
This commit is contained in:
Alex Yang
2023-07-07 16:13:32 +08:00
parent c23d31f912
commit d4dd352ebe
5 changed files with 48 additions and 41 deletions

View File

@@ -99,27 +99,7 @@ export const QuickSearch: FC = () => {
export const AllWorkspaceContext = ({
children,
}: PropsWithChildren): ReactElement => {
const currentWorkspaceId = useAtomValue(rootCurrentWorkspaceIdAtom);
const workspaces = useWorkspaces();
useEffect(() => {
const providers = workspaces
// ignore current workspace
.filter(workspace => workspace.id !== currentWorkspaceId)
.flatMap(workspace =>
workspace.blockSuiteWorkspace.providers.filter(
(provider): provider is PassiveDocProvider =>
'passive' in provider && provider.passive
)
);
providers.forEach(provider => {
provider.connect();
});
return () => {
providers.forEach(provider => {
provider.disconnect();
});
};
}, [currentWorkspaceId, workspaces]);
useWorkspaces();
return <>{children}</>;
};