11// @flow
2+ // Show task counts for currently displayed note, or all notes
23// Last updated 2025-04-22 for v0.7.0 by @jgclark
34
45import { displayTitle , percent } from '@helpers/general'
@@ -43,6 +44,9 @@ export async function showTaskCountForNote() {
4344
4445// Shows task statistics for all notes, ignoring @special folders
4546export async function showTaskCountForAll ( ) : Promise < void > {
47+ // Start this longish sort job in the background
48+ await CommandBar . onAsyncThread ( )
49+
4650 const regularNotes = DataStore . projectNotes . filter (
4751 ( n ) => ! n . filename . startsWith ( "@Templates" ) && ! n . filename . startsWith ( "@Trash" ) && ! n . filename . startsWith ( "@Archive" )
4852 )
@@ -61,6 +65,11 @@ export async function showTaskCountForAll(): Promise<void> {
6165
6266 // Iterate over all project notes, counting
6367 for ( let i = 0 ; i < allNotesCount ; i += 1 ) {
68+ // Show progress dialog every 50 notes
69+ if ( i % 100 === 0 ) {
70+ CommandBar . showLoading ( true , `Processing note ${ i . toLocaleString ( ) } of ${ allNotesCount . toLocaleString ( ) } ` , ( i / allNotesCount ) )
71+ }
72+
6473 const n = allNotes [ i ]
6574 const paragraphs = n . paragraphs
6675 const countParagraphsOfType = function ( types : Array < string > ) {
@@ -81,7 +90,9 @@ export async function showTaskCountForAll(): Promise<void> {
8190 // following is not quite the same as future. TODO: make future
8291 scheduledChecklistsTotal += countParagraphsOfType ( [ "checklistScheduled" ] )
8392 }
93+ CommandBar . showLoading ( false )
8494 const numNotesWithOpen = [ ...open . entries ( ) ] . length
95+ await CommandBar . onMainThread ( ) // no await
8596
8697 const closedTasksTotal = doneTasksTotal + cancelledTasksTotal
8798 const tasksTotal = openTasksTotal + closedTasksTotal
0 commit comments