Skip to content

Commit dba840a

Browse files
committed
add progress indicator for count all tasks
1 parent fee6cdc commit dba840a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

np.statistics/src/taskNoteStats.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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

45
import { displayTitle, percent } from '@helpers/general'
@@ -43,6 +44,9 @@ export async function showTaskCountForNote() {
4344

4445
// Shows task statistics for all notes, ignoring @special folders
4546
export 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

Comments
 (0)