Skip to content

Commit 8a9ef65

Browse files
committed
fix: Add a 0.1 second delay between redrawing Tasks search results.
Basically, many Tasks searches can take more than 0.1 second to render. But Obsidian and Tasks can parse many files during that 0.1 second span. 1. This speeds up start-up time in cases where there were Tasks queries open at start-up Obsidian, preventing double-redraws. 2. It eliminates lots of wasted redraws in open queries, when Obsidian is re-reading files that were edited externally (such as via Sync) and where bulk edits are made to files in the vault. Relates to issue #3283
1 parent f356edf commit 8a9ef65

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Obsidian/Cache.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import type { CachedMetadata, EventRef, HeadingCache, ListItemCache, SectionCache, Workspace } from 'obsidian';
1+
import {
2+
type CachedMetadata,
3+
type EventRef,
4+
type HeadingCache,
5+
type ListItemCache,
6+
type SectionCache,
7+
type Workspace,
8+
debounce,
9+
} from 'obsidian';
210
import { MetadataCache, Notice, TAbstractFile, TFile, Vault } from 'obsidian';
311
import { Mutex } from 'async-mutex';
412
import { TasksFile } from '../Scripting/TasksFile';
@@ -33,6 +41,12 @@ export class Cache {
3341
private state: State;
3442
private tasks: Task[];
3543

44+
private readonly notifySubscribersDebounced = debounce(
45+
() => this.notifySubscribersNotDebounced(),
46+
100, // Long enough to prevent successive redraws slowing performance; short enough for edits via context menus to appear snappy
47+
true,
48+
);
49+
3650
/**
3751
* We cannot know if this class will be instantiated because obsidian started
3852
* or because the plugin was activated later. This means we have to load the
@@ -111,7 +125,7 @@ export class Cache {
111125

112126
private notifySubscribers(): void {
113127
this.logger.debug('Cache.notifySubscribers()');
114-
this.notifySubscribersNotDebounced();
128+
this.notifySubscribersDebounced();
115129
}
116130

117131
private notifySubscribersNotDebounced(): void {

0 commit comments

Comments
 (0)