fix(server): limit rootDoc snapshot size (#12625)

close CLOUD-225

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
  - Added support for reading document blocks without requiring a workspace or root document snapshot.
- **Bug Fixes**
  - Improved handling of large workspace snapshots by skipping them when they exceed 10MB.
- **Tests**
  - Introduced new test cases to cover scenarios where root or workspace snapshots are absent.
  - Expanded snapshot tests for document block reading.
- **Refactor**
  - Updated several function signatures to make root and workspace snapshot parameters optional for greater flexibility.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-05-29 05:32:31 +00:00
parent 1eb9e62075
commit 39cb1afedb
8 changed files with 2367 additions and 14 deletions

View File

@@ -59,9 +59,9 @@ const bookmarkFlavours = new Set([
]);
function generateMarkdownPreviewBuilder(
yRootDoc: YDoc,
workspaceId: string,
blocks: BlockDocumentInfo[]
blocks: BlockDocumentInfo[],
yRootDoc?: YDoc
) {
function yblockToDraftModal(yblock: YBlock): DraftModel | null {
const flavour = yblock.get('sys:flavour') as string;
@@ -91,7 +91,7 @@ function generateMarkdownPreviewBuilder(
}
const titleMiddleware: TransformerMiddleware = ({ adapterConfigs }) => {
const pages = yRootDoc.getMap('meta').get('pages');
const pages = yRootDoc?.getMap('meta').get('pages');
if (!(pages instanceof YArray)) {
return;
}
@@ -442,7 +442,7 @@ export async function readAllBlocksFromDoc({
maxSummaryLength,
}: {
ydoc: YDoc;
rootYDoc: YDoc;
rootYDoc?: YDoc;
spaceId: string;
maxSummaryLength?: number;
}): Promise<
@@ -459,9 +459,9 @@ export async function readAllBlocksFromDoc({
const blockDocuments: BlockDocumentInfo[] = [];
const generateMarkdownPreview = generateMarkdownPreviewBuilder(
rootYDoc,
spaceId,
blockDocuments
blockDocuments,
rootYDoc
);
const blocks = ydoc.getMap<any>('blocks');