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 20 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
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
6 changes: 5 additions & 1 deletion packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository";
import { mapClusterNodesFrom } from "./utils/csm.mapper";
import {
fetchGitLogInParallel,
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,
getDefaultBranchName,
getGitConfig,
getGitLog,

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

View workflow job for this annotation

GitHub Actions / build (20.x)

'getGitLog' is defined but never used
getRepo,
} from "./utils/git.util";
import WebviewLoader from "./webview-loader";
Expand Down Expand Up @@ -59,6 +60,8 @@

const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath);

const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath);

const fetchCurrentBranch = async () => {
let branchName;
try {
Expand All @@ -75,8 +78,9 @@
};

const initialBaseBranchName = await fetchCurrentBranch();


const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => {
const gitLog = await getGitLog(gitPath, currentWorkspacePath);
const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin");

const { owner, repo: initialRepo } = getRepo(gitConfig);
Expand Down
79 changes: 79 additions & 0 deletions packages/vscode/src/utils/git.util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { COMMIT_SEPARATOR, GIT_LOG_SEPARATOR } from "@githru-vscode-ext/analysis-engine";
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 @@ -112,7 +116,7 @@
if (await isExecutable(file)) {
try {
return await getGitExecutable(file);
} catch (_) {}

Check warning on line 119 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 @@ -148,7 +152,7 @@
for (let i = 0; i < paths.length; i++) {
try {
return await getGitExecutable(paths[i]);
} catch (_) {}

Check warning on line 155 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 All @@ -170,6 +174,7 @@
"%B", // commit message (subject and body)
].join(GIT_LOG_SEPARATOR) +
GIT_LOG_SEPARATOR;

const args = [
"--no-pager",
"log",
Expand Down Expand Up @@ -198,6 +203,80 @@
});
}

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); // Buffer를 문자열로 변환 후 숫자로 변환
resolve(commitCount); // 숫자를 반환
Copy link
Contributor

Choose a reason for hiding this comment

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

한글 주석은 영어로 변경하거나,
필요없다면 삭제하는게 좋을 것 같습니다!

} 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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

? indentation 이 뭔가 안 맞는 느낌이네용?


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

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

console.log('__dirname:', __dirname);
Copy link
Contributor

Choose a reason for hiding this comment

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

정리하는 김에 console log도 정리해주면 좋을 것 같습니다.
필요한 것 or 런타임 디버깅에 유용한건 놔두고(혹은 부가 설명을 더 넣고), 나머지는 삭제하면 좋겠습니다

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

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
60 changes: 60 additions & 0 deletions packages/vscode/src/utils/git.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as cp from 'child_process';
import { parentPort, workerData } from 'worker_threads';

import { resolveSpawnOutput } from './git.util'

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




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

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();
3 changes: 1 addition & 2 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ 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);
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