Skip to content

Commit 65bd3d4

Browse files
committed
perf: use improved iso-git multiple-add API
1 parent 7f76533 commit 65bd3d4

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

src/shared/localShadowRepo.ts

+3-28
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@
99
import * as path from 'path';
1010
import * as os from 'os';
1111
import * as fs from 'fs';
12-
import { PerformanceObserver, performance } from 'perf_hooks';
1312
import { NamedPackageDir, Logger } from '@salesforce/core';
1413
import * as git from 'isomorphic-git';
1514
import { pathIsInFolder } from './functions';
16-
const obs = new PerformanceObserver((items) => {
17-
const item = items.getEntries()[0];
18-
console.log(`${item.name} : ${item.duration}`);
19-
performance.clearMarks(item.name);
20-
});
21-
22-
obs.observe({ type: 'measure' });
2315

2416
const cache = {};
2517
const gitIgnoreFileName = '.gitignore';
@@ -74,14 +66,11 @@ export class ShadowRepo {
7466

7567
// think of singleton behavior but unique to the projectPath
7668
public static async getInstance(options: ShadowRepoOptions): Promise<ShadowRepo> {
77-
performance.mark('start-instance');
7869
if (!ShadowRepo.instanceMap.has(options.projectPath)) {
7970
const newInstance = new ShadowRepo(options);
8071
await newInstance.init();
8172
ShadowRepo.instanceMap.set(options.projectPath, newInstance);
8273
}
83-
performance.mark('end-instance');
84-
performance.measure('getInstance', 'start-instance', 'end-instance');
8574
return ShadowRepo.instanceMap.get(options.projectPath) as ShadowRepo;
8675
}
8776

@@ -128,7 +117,6 @@ export class ShadowRepo {
128117
* @returns StatusRow[]
129118
*/
130119
public async getStatus(noCache = false): Promise<StatusRow[]> {
131-
performance.mark('start-status');
132120
if (!this.status || noCache) {
133121
try {
134122
// only ask about OS once but use twice
@@ -163,8 +151,6 @@ export class ShadowRepo {
163151
await this.unStashIgnoreFile();
164152
}
165153
}
166-
performance.mark('end-status');
167-
performance.measure('getStatus', 'start-status', 'end-status');
168154
return this.status;
169155
}
170156

@@ -251,20 +237,13 @@ export class ShadowRepo {
251237
deletedFiles = deletedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
252238
}
253239
try {
254-
performance.mark('start-add');
255-
// for (const filepath of [...new Set(deployedFiles)]) {
256-
// performance.mark(`item-add-${filepath}`);
257-
await git.add({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath: [...new Set(deployedFiles)], cache });
258-
// performance.mark(`item-end-${filepath}`);
259-
// performance.measure(`add-${filepath}`, `item-add-${filepath}`, `item-end-${filepath}`);
260-
// }
261-
performance.mark('end-add');
262-
performance.measure('git add', 'start-add', 'end-add');
240+
if (deployedFiles.length) {
241+
await git.add({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath: [...new Set(deployedFiles)], cache });
242+
}
263243

264244
for (const filepath of [...new Set(deletedFiles)]) {
265245
await git.remove({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath, cache });
266246
}
267-
performance.mark('start-commit');
268247

269248
const sha = await git.commit({
270249
fs,
@@ -274,8 +253,6 @@ export class ShadowRepo {
274253
author: { name: 'sfdx source tracking' },
275254
cache,
276255
});
277-
performance.mark('end-commit');
278-
performance.measure('git commit', 'start-commit', 'end-commit');
279256
// status changed as a result of the commit. This prevents users from having to run getStatus(true) to avoid cache
280257
if (needsUpdatedStatus) {
281258
await this.getStatus(true);
@@ -320,6 +297,4 @@ export class ShadowRepo {
320297
)
321298
);
322299
}
323-
324-
// private async addMultipleFiles(files: string[]): Promise<void> {}
325300
}

0 commit comments

Comments
 (0)