From 81df4751a367f2795bc0d165586650dbe8db73d6 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Sun, 19 Jul 2026 16:49:41 +0800 Subject: [PATCH] fix(server): blob gc (#15280) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### PR Dependency Tree * **PR #15280** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Bug Fixes** * Improved workspace document discovery so documents in trashed pages are correctly included when loading workspace content. * Fixed dragging collections into Favorites, including reordering collections within Favorites. * **Tests** * Added coverage for document projection behavior and collection drag-and-drop interactions. --- .../runtime/storage_runtime/doc_blob_refs.rs | 28 +++++++++++++++++-- tests/affine-local/e2e/drag-page.spec.ts | 20 +++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packages/backend/native/src/runtime/storage_runtime/doc_blob_refs.rs b/packages/backend/native/src/runtime/storage_runtime/doc_blob_refs.rs index fee9180055..1997a7d215 100644 --- a/packages/backend/native/src/runtime/storage_runtime/doc_blob_refs.rs +++ b/packages/backend/native/src/runtime/storage_runtime/doc_blob_refs.rs @@ -102,7 +102,7 @@ async fn load_workspace_doc_ids(pool: &PgPool, workspace_id: &str) -> RuntimeRes let Some(root) = load_current_doc(pool, workspace_id, workspace_id).await? else { return Ok(Vec::new()); }; - let ids = doc_loader::get_doc_ids_from_binary(root.blob, false) + let ids = doc_loader::get_doc_ids_from_binary(root.blob, true) .map_err(|err| RuntimeError::invalid_state(format!("Doc blob refs root doc parse failed: {err}")))?; let mut ids = ids; ids.sort(); @@ -229,7 +229,7 @@ mod tests { use super::*; #[test] - fn doc_blob_refs_extracts_image_refs() { + fn doc_blob_refs_projection_semantics() { let doc_id = "doc-blob-ref-test".to_string(); let blob = doc_loader::build_full_doc("Doc", "![Alt](blob://image-blob-key)", &doc_id).expect("doc fixture should build"); @@ -247,6 +247,30 @@ mod tests { .iter() .any(|reference| { reference.blob_key == "image-blob-key" && reference.flavour == "affine:image" }) ); + + let root = Doc::default(); + let mut meta = root.get_or_create_map("meta").expect("root meta should build"); + let mut pages = root.create_array().expect("root pages should build"); + let mut active = root.create_map().expect("active doc meta should build"); + active + .insert("id".to_string(), "active-doc") + .expect("active doc id should insert"); + pages.push(active).expect("active doc should insert"); + let mut trashed = root.create_map().expect("trashed doc meta should build"); + trashed + .insert("id".to_string(), "trashed-doc") + .expect("trashed doc id should insert"); + trashed + .insert("trash".to_string(), true) + .expect("trash flag should insert"); + pages.push(trashed).expect("trashed doc should insert"); + meta + .insert("pages".to_string(), pages) + .expect("root pages should insert"); + + let root = root.encode_update_v1().expect("root doc should encode"); + let ids = doc_loader::get_doc_ids_from_binary(root, true).expect("root doc ids should parse"); + assert_eq!(ids, vec!["active-doc", "trashed-doc"]); } } diff --git a/tests/affine-local/e2e/drag-page.spec.ts b/tests/affine-local/e2e/drag-page.spec.ts index dbe174c1d0..93c5e357eb 100644 --- a/tests/affine-local/e2e/drag-page.spec.ts +++ b/tests/affine-local/e2e/drag-page.spec.ts @@ -30,7 +30,11 @@ const dragToFavourites = async ( const favourites = page.getByTestId( 'navigation-panel-favorite-category-divider' ); - await dragTo(page, dragItem, favourites); + if (type === 'collection') { + await dragItem.dragTo(favourites); + } else { + await dragTo(page, dragItem, favourites); + } const item = page .getByTestId(`navigation-panel-favorites`) .locator(`[data-testid="navigation-panel-${type}-${id}"]`); @@ -168,7 +172,12 @@ test('drag a collection to favourites', async ({ page }) => { await page.waitForTimeout(500); const collection = await createCollection(page, 'test collection'); const collectionId = getCurrentCollectionIdFromUrl(page); - await dragToFavourites(page, collection, collectionId, 'collection'); + await dragToFavourites( + page, + collection.locator('[data-affine-draggable]'), + collectionId, + 'collection' + ); }); test('items in favourites can be reordered by dragging', async ({ page }) => { @@ -183,7 +192,12 @@ test('items in favourites can be reordered by dragging', async ({ page }) => { { const collection = await createCollection(page, 'test collection'); const collectionId = getCurrentCollectionIdFromUrl(page); - await dragToFavourites(page, collection, collectionId, 'collection'); + await dragToFavourites( + page, + collection.locator('[data-affine-draggable]'), + collectionId, + 'collection' + ); } // assert the order of the items in favourites