Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[engine] feature/712 브랜치에서 작업한 내용을 main 브랜치에 반영 #766

Merged
merged 23 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42963dd
Merge commit '3eab9812735ec87872c11643a126427142f49b25'
BeA-Pro Sep 8, 2024
2f913fb
feat: 멀티쓰레드 도입
BeA-Pro Sep 8, 2024
b8ae0a3
feat: git.helper 주석 제거
BeA-Pro Sep 8, 2024
3b1da9c
Merge pull request #713 from BeA-Pro/main
BeA-Pro Sep 12, 2024
8eade2e
Merge pull request #737 from githru/main
BeA-Pro Sep 29, 2024
861c262
fix: package-lock.json 최신화
BeA-Pro Sep 29, 2024
1707efe
feature/#712 브랜치 package-lock.json 버전 최신화
BeA-Pro Sep 29, 2024
a739c3f
[engine] #713 요구사항 적용
BeA-Pro Sep 29, 2024
ed7ed3b
[engine] 변수의 실제 역할로 표현
BeA-Pro Oct 1, 2024
bfaee30
[engine] #713 요구사항 적용
BeA-Pro Oct 1, 2024
d5536b3
[engine] 로그 개수에 맞는 쓰레드 생성
BeA-Pro Oct 1, 2024
632560d
[engine] 로그 개수에 맞는 쓰레드 생성
BeA-Pro Oct 2, 2024
a18fb5a
[engine] 최대 쓰레드 수 3개 제한 및 git 로그 최초 한 번만 불러오기
BeA-Pro Oct 6, 2024
7952cd0
[engine] 불필요한 로그 제거
BeA-Pro Oct 6, 2024
be3931a
[engine] 임계 쓰레드 수, 코어 수 변수명 추가
BeA-Pro Oct 7, 2024
3ffabfb
[engine] 최대 쓰레드 수 3개 제한 및 git 로그 최초 한 번만 불러오기
BeA-Pro Oct 7, 2024
cb8480b
[engine] main 브랜치 병합을 위한 동기화 작업
BeA-Pro Oct 7, 2024
7b7ff09
[engine] feature/712 브랜치와 main 브랜치 병합을 위한 동기화 작업
BeA-Pro Oct 7, 2024
4488e5d
[engine] git.worker.ts에 새로운 git format 적용
BeA-Pro Oct 7, 2024
e9ad183
[engine] git.worker.ts에 새로운 git format 적용
BeA-Pro Oct 7, 2024
883453d
[engine] 주석 제거 및 prettier 적용
BeA-Pro Oct 15, 2024
15a87ef
[engine] git log parsing 부분 적용
BeA-Pro Oct 22, 2024
fb7975a
fix: 불필요한 주석 제거 및 빌드 문제 해결
BeA-Pro Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/analysis-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export class AnalysisEngine {
if (this.isDebugMode) console.log("baseBranchName: ", this.baseBranchName);

const commitRaws = getCommitRaws(this.gitLog);
if (this.isDebugMode) console.log("commitRaws: ", commitRaws);
if (this.isDebugMode){
console.log("commitRaws: ", commitRaws);
}

const commitDict = buildCommitDict(commitRaws);
if (this.isDebugMode) console.log("commitDict: ", commitDict);
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
}
],
"simple-import-sort/exports": "error",
"no-duplicate-imports": "error"
"no-duplicate-imports": "error",
"import/no-commonjs": "off"
},
"overrides": [
{
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository";
import { mapClusterNodesFrom } from "./utils/csm.mapper";
import {
fetchGitLogInParallel,

Check warning on line 10 in packages/vscode/src/extension.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'fetchGitLogInParallel' is defined but never used
Copy link
Contributor

Choose a reason for hiding this comment

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

unused는 추후에 삭제 해주시면 좋겠습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵!

findGit,
getBranches,
getCurrentBranchName,
Expand Down Expand Up @@ -77,6 +78,7 @@
};

const initialBaseBranchName = await fetchCurrentBranch();

const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => {
const gitLog = await getGitLog(gitPath, currentWorkspacePath);
const { owner, repo: initialRepo } = getRepo(gitConfig);
Expand Down
66 changes: 66 additions & 0 deletions packages/vscode/src/utils/git.util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as cp from "child_process";
import * as fs from "fs";
import os from "os";
import * as path from "path";
import { Worker } from "worker_threads";

export interface GitExecutable {
readonly path: string;
Expand Down Expand Up @@ -111,7 +113,7 @@
if (await isExecutable(file)) {
try {
return await getGitExecutable(file);
} catch (_) {}

Check warning on line 116 in packages/vscode/src/utils/git.util.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Empty block statement
}
}
return Promise.reject<GitExecutable>();
Expand Down Expand Up @@ -147,7 +149,7 @@
for (let i = 0; i < paths.length; i++) {
try {
return await getGitExecutable(paths[i]);
} catch (_) {}

Check warning on line 152 in packages/vscode/src/utils/git.util.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Empty block statement
}
throw new Error("None of the provided paths are a Git executable");
}
Expand Down Expand Up @@ -197,6 +199,70 @@
});
}

export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

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

드뎌 메인으로 들어오는군요 : )

const BASE_10 = 10;
return new Promise((resolve, reject) => {
const args = ["rev-list", "--count", "--all"];

resolveSpawnOutput(
cp.spawn(gitPath, args, {
cwd: currentWorkspacePath,
env: Object.assign({}, process.env),
})
).then(([status, stdout, stderr]) => {
const { code, error } = status;

if (code === 0 && !error) {
const commitCount = parseInt(stdout.toString().trim(), BASE_10);
resolve(commitCount);
} else {
reject(stderr);
}
});
});
}

export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise<string> {
const numCores = os.cpus().length;

const totalCnt = await getLogCount(gitPath, currentWorkspacePath);
let numberOfThreads = 1;

const taskThreshold = 1000;
const coreCountThreshold = 4;

if (totalCnt > taskThreshold) {
if (numCores < coreCountThreshold) numberOfThreads = 2;
else numberOfThreads = 3;
}
Comment on lines +228 to +237
Copy link
Member

Choose a reason for hiding this comment

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

수 많은 테스트로 도출한 최적의 파라미터 값! 👍👍👍👍


const chunkSize = Math.ceil(totalCnt / numberOfThreads);
const promises: Promise<string>[] = [];

for (let i = 0; i < numberOfThreads; i++) {
const skipCount = i * chunkSize;
const limitCount = chunkSize;

const worker = new Worker(path.resolve(__dirname, "./worker.js"), {
workerData: {
gitPath,
currentWorkspacePath,
skipCount,
limitCount,
},
});

promises.push(
new Promise((resolve, reject) => {
worker.on("message", resolve);
worker.on("error", reject);
})
);
}

return Promise.all(promises).then((logs) => logs.join("\n"));
}

export async function getGitConfig(
gitPath: string,
currentWorkspacePath: string,
Expand Down
59 changes: 59 additions & 0 deletions packages/vscode/src/utils/git.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as cp from "child_process";
import { parentPort, workerData } from "worker_threads";

import { resolveSpawnOutput } from "./git.util";

const { gitPath, currentWorkspacePath, skipCount, limitCount } = workerData;

async function getPartialGitLog() {
const gitLogFormat =
"%n%n" +
[
"%H", // commit hash (id)
"%P", // parent hashes
"%D", // ref names (branches, tags)
"%an", // author name
"%ae", // author email
"%ad", // author date
"%cn", // committer name
"%ce", // committer email
"%cd", // committer date
"%w(0,0,4)%s", // commit message subject
"%b", // commit message body
].join("%n");

const args = [
"--no-pager",
"log",
"--all",
"--parents",
"--numstat",
"--date-order",
`--pretty=format:${gitLogFormat}`,
"--decorate",
"-c",
`--skip=${skipCount}`,
`-n ${limitCount}`,
];

resolveSpawnOutput(
cp.spawn(gitPath, args, {
cwd: currentWorkspacePath,
env: Object.assign({}, process.env),
})
)
.then(([status, stdout, stderr]) => {
const { code, error } = status;

if (code === 0 && !error && parentPort !== null) {
parentPort.postMessage(stdout.toString());
} else {
if (parentPort !== null) parentPort.postMessage(stderr);
}
})
.catch((error) => {
console.error("Spawn Error:", error);
});
}

getPartialGitLog();
9 changes: 3 additions & 6 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default class WebviewLoader implements vscode.Disposable {
const { fetchClusterNodes, fetchBranches, fetchCurrentBranch, fetchGithubInfo } = fetcher;
const viewColumn = vscode.ViewColumn.One;

//캐시 초기화
console.log("Initialize cache data");
context.workspaceState.keys().forEach((key) => {
context.workspaceState.update(key, undefined);
Expand All @@ -37,21 +36,19 @@ export default class WebviewLoader implements vscode.Disposable {
const { command, payload } = message;

if (command === "fetchAnalyzedData" || command === "refresh") {
const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch());
try {
const baseBranchName = (payload && JSON.parse(payload)) ?? (await fetchCurrentBranch());
const storedAnalyzedData = context.workspaceState.get<ClusterNode[]>(
`${ANALYZE_DATA_KEY}_${baseBranchName}`
);
let analyzedData = storedAnalyzedData;
analyzedData = storedAnalyzedData;
if (!storedAnalyzedData) {
console.log("No cache Data");
console.log("baseBranchName : ", baseBranchName);
analyzedData = await fetchClusterNodes(baseBranchName);
context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData);
} else console.log("Cache data exists");

// 현재 캐싱된 Branch
console.log("Current Stored data");
context.workspaceState.keys().forEach((key) => {
console.log(key);
Expand All @@ -76,10 +73,10 @@ export default class WebviewLoader implements vscode.Disposable {
payload: branches,
});
}

if (command === "fetchGithubInfo") {
const githubInfo = await fetchGithubInfo();
await this.respondToMessage({
await this.respondToMessage({
...message,
payload: githubInfo,
});
Expand Down
7 changes: 5 additions & 2 deletions packages/vscode/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ const extensionConfig = {
target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')

entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
entry: {
extension: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
worker: "./src/utils/git.worker.ts"
Copy link
Member

Choose a reason for hiding this comment

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

여기서 worker가 추가되는군요 😁

},
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, "dist"),
filename: "extension.js",
filename: "[name].js",
libraryTarget: "commonjs2",
},
externals: {
Expand Down
Loading