Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 969c2e4

Browse files
committedSep 18, 2024··
chore: forceignore caching
1 parent ebdff15 commit 969c2e4

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed
 

‎src/resolve/forceIgnore.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class ForceIgnore {
1818
private readonly parser?: Ignore;
1919
private readonly forceIgnoreDirectory?: string;
2020
private DEFAULT_IGNORE = ['**/*.dup', '**/.*', '**/package2-descriptor.json', '**/package2-manifest.json'];
21+
private isPathIgnored = new Map<string, boolean>();
2122

2223
public constructor(forceIgnorePath = '') {
2324
try {
@@ -64,19 +65,35 @@ export class ForceIgnore {
6465

6566
public denies(fsPath: SourcePath): boolean {
6667
if (!this.parser || !this.forceIgnoreDirectory) return false;
68+
// we've already figured out if this path is ignored or not, just get it from the cache
69+
if (this.isPathIgnored.has(fsPath)) return this.isPathIgnored.get(fsPath)!;
70+
71+
let result: boolean;
6772
try {
68-
return this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
73+
result = this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
6974
} catch (e) {
70-
return false;
75+
result = false;
7176
}
77+
78+
this.isPathIgnored.set(fsPath, result);
79+
80+
return result;
7281
}
7382

7483
public accepts(fsPath: SourcePath): boolean {
7584
if (!this.parser || !this.forceIgnoreDirectory) return true;
85+
// we've already figured out if this path is ignored or not, just get it from the cache
86+
// the cache is set for 'denies' so for accept, negate the result
87+
if (this.isPathIgnored.has(fsPath)) return !this.isPathIgnored.get(fsPath);
88+
89+
let result: boolean;
7690
try {
77-
return !this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
91+
result = !this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
7892
} catch (e) {
79-
return true;
93+
result = true;
8094
}
95+
// since the cache has the 'denies' result, negate the result here
96+
this.isPathIgnored.set(fsPath, !result);
97+
return result;
8198
}
8299
}

‎src/resolve/sourceComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class SourceComponent implements MetadataComponent {
287287
}
288288

289289
private parse<T extends JsonMap>(contents: string): T {
290-
const parsed = parser.parse(String(contents)) as T;
290+
const parsed = parser.parse(contents) as T;
291291
const [firstElement] = Object.keys(parsed);
292292
if (firstElement === this.type.name) {
293293
return parsed;

‎src/resolve/treeContainers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd
2525
* Extend this base class to implement a custom container.
2626
*/
2727
export abstract class TreeContainer {
28+
protected fileContentMap: Map<string, Buffer> = new Map<string, Buffer>();
2829
/**
2930
* Searches for a metadata component file in a container directory.
3031
*
@@ -110,7 +111,12 @@ export class NodeFSTreeContainer extends TreeContainer {
110111
}
111112

112113
public readFileSync(fsPath: SourcePath): Buffer {
113-
return readFileSync(fsPath);
114+
if (this.fileContentMap.has(fsPath)) {
115+
return this.fileContentMap.get(fsPath)!;
116+
} else {
117+
this.fileContentMap.set(fsPath, readFileSync(fsPath));
118+
return this.fileContentMap.get(fsPath)!;
119+
}
114120
}
115121

116122
public stream(fsPath: SourcePath): Readable {

‎test/resolve/forceIgnore.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ describe('ForceIgnore', () => {
7171
expect(fi.accepts(join('force-app', 'main', 'default', 'classes'))).to.be.true;
7272
});
7373

74-
/**
75-
* TODO: Rework when approach to default patterns changes. We should be able
76-
* to generally test the defaults system.
77-
*/
7874
describe('Defaults with new parser', () => {
7975
let forceIgnore: ForceIgnore;
8076
const root = join('some', 'path');
@@ -84,8 +80,8 @@ describe('ForceIgnore', () => {
8480
forceIgnore = new ForceIgnore();
8581
});
8682

87-
// the example's index here is specific to the rules order in ForceIgnore.DEFAULT_IGNORE
88-
const forceIgnoreExamples = ['abc.dup', '.xyz', 'package2-descriptor.json', 'package2-manifest.json'];
83+
// these examples test the default behaviors - check the cache behavior with the duplicate 'abc.dup'
84+
const forceIgnoreExamples = ['abc.dup', 'abc.dup', '.xyz', 'package2-descriptor.json', 'package2-manifest.json'];
8985
forceIgnoreExamples.map((ignore) => {
9086
it(`Should ignore files starting with a ${ignore}`, () => {
9187
const testPath = join(root, ignore);

2 commit comments

Comments
 (2)

svc-cli-bot commented on Sep 18, 2024

@svc-cli-bot
Collaborator

Benchmark

Benchmark suite Current: 969c2e4 Previous: 586865e Ratio
eda-componentSetCreate-linux 239 ms 237 ms 1.01
eda-sourceToMdapi-linux 2245 ms 2290 ms 0.98
eda-sourceToZip-linux 1831 ms 1899 ms 0.96
eda-mdapiToSource-linux 2969 ms 3024 ms 0.98
lotsOfClasses-componentSetCreate-linux 389 ms 429 ms 0.91
lotsOfClasses-sourceToMdapi-linux 3612 ms 3807 ms 0.95
lotsOfClasses-sourceToZip-linux 3121 ms 3224 ms 0.97
lotsOfClasses-mdapiToSource-linux 3531 ms 3616 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 685 ms 766 ms 0.89
lotsOfClassesOneDir-sourceToMdapi-linux 6354 ms 6659 ms 0.95
lotsOfClassesOneDir-sourceToZip-linux 5352 ms 5804 ms 0.92
lotsOfClassesOneDir-mdapiToSource-linux 6860 ms 6570 ms 1.04

This comment was automatically generated by workflow using github-action-benchmark.

svc-cli-bot commented on Sep 18, 2024

@svc-cli-bot
Collaborator

Benchmark

Benchmark suite Current: 969c2e4 Previous: 586865e Ratio
eda-componentSetCreate-win32 678 ms 664 ms 1.02
eda-sourceToMdapi-win32 4461 ms 4582 ms 0.97
eda-sourceToZip-win32 3059 ms 3219 ms 0.95
eda-mdapiToSource-win32 6212 ms 6082 ms 1.02
lotsOfClasses-componentSetCreate-win32 1247 ms 1286 ms 0.97
lotsOfClasses-sourceToMdapi-win32 8257 ms 8359 ms 0.99
lotsOfClasses-sourceToZip-win32 5396 ms 5338 ms 1.01
lotsOfClasses-mdapiToSource-win32 8556 ms 8505 ms 1.01
lotsOfClassesOneDir-componentSetCreate-win32 2221 ms 2234 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-win32 14988 ms 14810 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 10460 ms 9949 ms 1.05
lotsOfClassesOneDir-mdapiToSource-win32 14594 ms 15320 ms 0.95

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.