perf(cli): compile ignore patterns once

Long-running CLI processes rebuilt the same minimatch ASTs for every checked path.

Compile patterns while loading ignore rules and reuse them until the rules are reloaded.

Refs #1006
This commit is contained in:
Ouyang Xingyuan
2026-07-13 10:47:35 +08:00
parent 9c375bd6fd
commit f28d886603
2 changed files with 44 additions and 5 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
import { minimatch } from "minimatch";
import { Minimatch } from "minimatch";
import { fsPromises as fs, path } from "@/apps/cli/node-compat";
/**
@@ -17,7 +17,7 @@ import { fsPromises as fs, path } from "@/apps/cli/node-compat";
* Missing files (`.livesync/ignore` or `.gitignore`) are silently skipped.
*/
export class IgnoreRules {
private patterns: string[] = [];
private patterns: Minimatch[] = [];
constructor(private vaultPath: string) {}
@@ -108,7 +108,7 @@ export class IgnoreRules {
`Remove it from .livesync/ignore or use a separate include/exclude file.`
);
}
this.patterns.push(this._normalisePattern(raw));
this.patterns.push(new Minimatch(this._normalisePattern(raw), { dot: true }));
}
/**
@@ -124,6 +124,6 @@ export class IgnoreRules {
}
// Normalise to forward slashes for minimatch.
const normalised = relativePath.replace(/\\/g, "/");
return this.patterns.some((p) => minimatch(normalised, p, { dot: true }));
return this.patterns.some((pattern) => pattern.match(normalised));
}
}