Skip to content

Commit

Permalink
chore: forceignore caching
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 18, 2024
1 parent ebdff15 commit 969c2e4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
25 changes: 21 additions & 4 deletions src/resolve/forceIgnore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ForceIgnore {
private readonly parser?: Ignore;
private readonly forceIgnoreDirectory?: string;
private DEFAULT_IGNORE = ['**/*.dup', '**/.*', '**/package2-descriptor.json', '**/package2-manifest.json'];
private isPathIgnored = new Map<string, boolean>();

public constructor(forceIgnorePath = '') {
try {
Expand Down Expand Up @@ -64,19 +65,35 @@ export class ForceIgnore {

public denies(fsPath: SourcePath): boolean {
if (!this.parser || !this.forceIgnoreDirectory) return false;
// we've already figured out if this path is ignored or not, just get it from the cache
if (this.isPathIgnored.has(fsPath)) return this.isPathIgnored.get(fsPath)!;

let result: boolean;
try {
return this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
result = this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
} catch (e) {
return false;
result = false;
}

this.isPathIgnored.set(fsPath, result);

return result;
}

public accepts(fsPath: SourcePath): boolean {
if (!this.parser || !this.forceIgnoreDirectory) return true;
// we've already figured out if this path is ignored or not, just get it from the cache
// the cache is set for 'denies' so for accept, negate the result
if (this.isPathIgnored.has(fsPath)) return !this.isPathIgnored.get(fsPath);

let result: boolean;
try {
return !this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
result = !this.parser.ignores(relative(this.forceIgnoreDirectory, fsPath));
} catch (e) {
return true;
result = true;
}
// since the cache has the 'denies' result, negate the result here
this.isPathIgnored.set(fsPath, !result);
return result;
}
}
2 changes: 1 addition & 1 deletion src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class SourceComponent implements MetadataComponent {
}

private parse<T extends JsonMap>(contents: string): T {
const parsed = parser.parse(String(contents)) as T;
const parsed = parser.parse(contents) as T;
const [firstElement] = Object.keys(parsed);
if (firstElement === this.type.name) {
return parsed;
Expand Down
8 changes: 7 additions & 1 deletion src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd
* Extend this base class to implement a custom container.
*/
export abstract class TreeContainer {
protected fileContentMap: Map<string, Buffer> = new Map<string, Buffer>();
/**
* Searches for a metadata component file in a container directory.
*
Expand Down Expand Up @@ -110,7 +111,12 @@ export class NodeFSTreeContainer extends TreeContainer {
}

public readFileSync(fsPath: SourcePath): Buffer {
return readFileSync(fsPath);
if (this.fileContentMap.has(fsPath)) {
return this.fileContentMap.get(fsPath)!;
} else {
this.fileContentMap.set(fsPath, readFileSync(fsPath));
return this.fileContentMap.get(fsPath)!;
}
}

public stream(fsPath: SourcePath): Readable {
Expand Down
8 changes: 2 additions & 6 deletions test/resolve/forceIgnore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ describe('ForceIgnore', () => {
expect(fi.accepts(join('force-app', 'main', 'default', 'classes'))).to.be.true;
});

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

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

2 comments on commit 969c2e4

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.