diff --git a/app/lib/src/rust/api/graph.dart b/app/lib/src/rust/api/graph.dart index 3494b46..3c49ca1 100644 --- a/app/lib/src/rust/api/graph.dart +++ b/app/lib/src/rust/api/graph.dart @@ -98,10 +98,11 @@ abstract class SynapseGraph implements RustOpaqueInterface { /// journal); otherwise at the newest journal strictly before `before`. Future> journals({String? before, required int limit}); - /// Pages that are probably leftovers of Logseq: its built-ins and pages with - /// `type:: system`. Only the organisational files (`contents`, `card`, `favorites`, - /// `hls__*`) and empty pages are preselected, and never a hub: a built-in title such as - /// `todo` may hold real content. + /// Pages worth cleaning up: leftovers of Logseq (its built-ins and pages with + /// `type:: system`) and empty pages (no text in any block, not a hub, no type, tags or + /// description). Of the Logseq ones only the organisational files (`contents`, `card`, + /// `favorites`, `hls__*`) and empty pages are preselected, and never a hub: a built-in + /// title such as `todo` may hold real content. Empty pages are all preselected. Future> legacyCandidates(); /// Pages ordered by last update, most recent first. diff --git a/app/lib/src/rust/frb_generated.dart b/app/lib/src/rust/frb_generated.dart index bea5243..f605c8a 100644 --- a/app/lib/src/rust/frb_generated.dart +++ b/app/lib/src/rust/frb_generated.dart @@ -5290,10 +5290,11 @@ class SynapseGraphImpl extends RustOpaque implements SynapseGraph { limit: limit, ); - /// Pages that are probably leftovers of Logseq: its built-ins and pages with - /// `type:: system`. Only the organisational files (`contents`, `card`, `favorites`, - /// `hls__*`) and empty pages are preselected, and never a hub: a built-in title such as - /// `todo` may hold real content. + /// Pages worth cleaning up: leftovers of Logseq (its built-ins and pages with + /// `type:: system`) and empty pages (no text in any block, not a hub, no type, tags or + /// description). Of the Logseq ones only the organisational files (`contents`, `card`, + /// `favorites`, `hls__*`) and empty pages are preselected, and never a hub: a built-in + /// title such as `todo` may hold real content. Empty pages are all preselected. Future> legacyCandidates() => RustLib.instance.api .crateApiGraphSynapseGraphLegacyCandidates(that: this); diff --git a/app/lib/src/views/all_pages_view.dart b/app/lib/src/views/all_pages_view.dart index c0021c1..918155e 100644 --- a/app/lib/src/views/all_pages_view.dart +++ b/app/lib/src/views/all_pages_view.dart @@ -374,21 +374,43 @@ class _CleanupDialogState extends State { final colors = context.colors; final items = widget.candidates; return AlertDialog( - title: const Text('Remove legacy Logseq pages'), + title: const Text('Clean up pages'), content: SizedBox( width: 460, child: items.isEmpty ? Text( - 'No legacy pages found.', + 'Nothing to clean up.', style: TextStyle(color: colors.muted), ) : Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - 'This deletes the selected pages and their blocks.', - style: TextStyle(fontSize: 13, color: colors.muted), + Row( + children: [ + Expanded( + child: Text( + 'Empty pages and Logseq leftovers. This deletes the ' + 'selected pages and their blocks.', + style: TextStyle(fontSize: 13, color: colors.muted), + ), + ), + TextButton( + key: const Key('cleanup-toggle-all'), + onPressed: () => setState(() { + if (_checked.length == items.length) { + _checked.clear(); + } else { + _checked.addAll([for (final c in items) c.id]); + } + }), + child: Text( + _checked.length == items.length + ? 'Select none' + : 'Select all', + ), + ), + ], ), const SizedBox(height: 8), Flexible( diff --git a/app/test/hubs_ui_test.dart b/app/test/hubs_ui_test.dart index 1aeefeb..479bc8b 100644 --- a/app/test/hubs_ui_test.dart +++ b/app/test/hubs_ui_test.dart @@ -515,7 +515,7 @@ void main() { await pump(tester, b, home: const Scaffold(body: AllPagesView())); await tester.tap(find.text('Clean up')); await settle(tester); - expect(find.text('Remove legacy Logseq pages'), findsOneWidget); + expect(find.text('Clean up pages'), findsOneWidget); expect(find.text('Delete (2)'), findsOneWidget); // Uncheck "card". await tester.tap( @@ -538,7 +538,7 @@ void main() { await pump(tester, demo(), home: const Scaffold(body: AllPagesView())); await tester.tap(find.text('Clean up')); await settle(tester); - expect(find.text('No legacy pages found.'), findsOneWidget); + expect(find.text('Nothing to clean up.'), findsOneWidget); }); } diff --git a/crates/synapse-ffi/src/api/structure.rs b/crates/synapse-ffi/src/api/structure.rs index ec05071..e0eff1c 100644 --- a/crates/synapse-ffi/src/api/structure.rs +++ b/crates/synapse-ffi/src/api/structure.rs @@ -204,15 +204,24 @@ impl SynapseGraph { )) } - /// Pages that are probably leftovers of Logseq: its built-ins and pages with - /// `type:: system`. Only the organisational files (`contents`, `card`, `favorites`, - /// `hls__*`) and empty pages are preselected, and never a hub: a built-in title such as - /// `todo` may hold real content. + /// Pages worth cleaning up: leftovers of Logseq (its built-ins and pages with + /// `type:: system`) and empty pages (no text in any block, not a hub, no type, tags or + /// description). Of the Logseq ones only the organisational files (`contents`, `card`, + /// `favorites`, `hls__*`) and empty pages are preselected, and never a hub: a built-in + /// title such as `todo` may hold real content. Empty pages are all preselected. pub fn legacy_candidates(&self) -> Result> { let g = self.lock(); let mut out = Vec::new(); for p in g.list_pages(false, u32::MAX, 0)? { let key = title_key(&p.title); + let tree = g.page_tree(p.id)?; + let blocks = tree.len() as u32; + let blank = tree.iter().all(|(_, b)| b.content.trim().is_empty()); + let empty = blank + && !p.is_hub() + && p.page_type().is_none() + && p.tags.is_empty() + && p.description.trim().is_empty(); let reason = if is_legacy_page(&p.title) { if key.starts_with("hls__") { "Logseq PDF highlights" @@ -221,10 +230,11 @@ impl SynapseGraph { } } else if p.properties.get("type").and_then(|v| v.as_str()) == Some("system") { "type:: system" + } else if empty { + "Empty" } else { continue; }; - let blocks = g.page_tree(p.id)?.len() as u32; let organisational = matches!(key.as_str(), "contents" | "card" | "favorites") || key.starts_with("hls__"); out.push(LegacyCandidate { @@ -232,7 +242,7 @@ impl SynapseGraph { title: p.title.clone(), reason: reason.into(), blocks, - preselected: !p.is_hub() && (blocks == 0 || organisational), + preselected: !p.is_hub() && (empty || blocks == 0 || organisational), }); } out.sort_by_key(|c| title_key(&c.title)); diff --git a/docs/architecture.md b/docs/architecture.md index 38cb404..caa38ec 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -47,6 +47,8 @@ crates may add their own tables to the same database (prefix them: `search_*`, ` the first; `PageKind` has no `Tag` any more and "tag" parses as a note. - In the graph (`synapse-ffi`) every tag in use is a virtual node (`GraphNode.is_tag`, id `tag:`, no page), with a `TAGGED` edge from each tagged page (type included). + A tag named like a hub in the graph uses the hub's node instead; its members, already + linked by `CONTAINS`, get no `TAGGED` edge. - Known limitations: replicas still on the old schema may overwrite tags with stale values (LWW per page), and `rename_tag` is a bulk page edit, so concurrent edits on another replica can undo part of it. - Exports use `synapse-tags::` and `synapse-type::` (see `history.md`). @@ -90,8 +92,8 @@ Two orthogonal ways to organise pages. a hub; `convert_to_note` keeps such blocks. Clients older than schema v3 drop `kind`, `description` and `hubs` when they upsert a page, so every client must be on v3. - Logseq built-ins (`contents`, `TODO`, `hls__*`, ...) are recognised by `is_legacy_page`; the - app offers to purge them (`legacy_candidates` / `purge_pages` in `synapse-ffi`). The importer - only skips a narrower set (see `import.md`). + app offers to purge them, together with empty pages (`legacy_candidates` / `purge_pages` in + `synapse-ffi`). The importer only skips a narrower set (see `import.md`). ## Temporal model - `journal_neighbors(date)` gives the previous/next existing journal (episodic chain).