Skip to content

Commit 3a60eba

Browse files
committed
feat: pullRemote optimizations and "profiling"
1 parent 2950617 commit 3a60eba

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/proxy/processors/push-action/pullRemote.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import gitHttpClient from 'isomorphic-git/http/node';
66
const dir = './.remote';
77

88
const exec = async (req: any, action: Action): Promise<Action> => {
9+
console.log('TIME: pullRemoteStart');
10+
const startTime = Date.now();
911
const step = new Step('pullRemote');
1012

1113
try {
12-
action.proxyGitPath = `${dir}/${action.timestamp}`;
13-
14-
step.log(`Creating folder ${action.proxyGitPath}`);
14+
action.proxyGitPath = `${dir}/${action.id}`;
1515

1616
if (!fs.existsSync(dir)) {
1717
fs.mkdirSync(dir);
1818
}
1919

2020
if (!fs.existsSync(action.proxyGitPath)) {
21+
step.log(`Creating folder ${action.proxyGitPath}`);
2122
fs.mkdirSync(action.proxyGitPath, 0o755);
2223
}
2324

@@ -29,18 +30,31 @@ const exec = async (req: any, action: Action): Promise<Action> => {
2930
.toString()
3031
.split(':');
3132

32-
await git.clone({
33-
fs,
34-
http: gitHttpClient,
35-
url: action.url,
36-
onAuth: () => ({
37-
username,
38-
password,
39-
}),
40-
dir: `${action.proxyGitPath}/${action.repoName}`,
41-
});
33+
if (!fs.existsSync(`${action.proxyGitPath}/${action.repoName}`)) {
34+
console.log('Clone: ', action.url);
35+
await git.clone({
36+
fs,
37+
http: gitHttpClient,
38+
url: action.url,
39+
dir: `${action.proxyGitPath}/${action.repoName}`,
40+
onAuth: () => ({ username, password }),
41+
singleBranch: true,
42+
depth: 1,
43+
});
44+
} else {
45+
console.log('Fetch: ', action.url);
46+
await git.fetch({
47+
fs,
48+
http: gitHttpClient,
49+
url: action.url,
50+
dir: `${action.proxyGitPath}/${action.repoName}`,
51+
onAuth: () => ({ username, password }),
52+
singleBranch: true,
53+
depth: 1,
54+
});
55+
}
4256

43-
console.log('Clone Success: ', action.url);
57+
console.log('Clone/Fetch Success: ', action.url);
4458

4559
step.log(`Completed ${cmd}`);
4660
step.setContent(`Completed ${cmd}`);
@@ -50,6 +64,9 @@ const exec = async (req: any, action: Action): Promise<Action> => {
5064
} finally {
5165
action.addStep(step);
5266
}
67+
const endTime = Date.now();
68+
const duration = endTime - startTime;
69+
console.log(`TIME: pullRemote completed in ${duration}ms`);
5370
return action;
5471
};
5572

src/proxy/routes/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ const proxyFilter: ProxyOptions['filter'] = async (req, res) => {
4646
return false;
4747
}
4848

49+
console.log('TIME: executeChain start');
50+
const startTime = Date.now();
4951
const action = await executeChain(req, res);
52+
const endTime = Date.now();
53+
const duration = endTime - startTime;
54+
console.log(`TIME: executeChain completed in ${duration}ms`);
5055

5156
if (action.error || action.blocked) {
5257
res.set('content-type', 'application/x-git-receive-pack-result');

0 commit comments

Comments
 (0)