From 2f913fb0ab48c849b6b07317e4b1b6a2c383dd4a Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Mon, 9 Sep 2024 02:43:12 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20=EB=A9=80=ED=8B=B0=EC=93=B0?= =?UTF-8?q?=EB=A0=88=EB=93=9C=20=EB=8F=84=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/analysis-engine/src/index.ts | 4 +- packages/vscode/.eslintrc.json | 3 +- packages/vscode/src/extension.ts | 11 +++- packages/vscode/src/utils/git.util.ts | 67 +++++++++++++++++++++++++ packages/vscode/src/utils/git.worker.ts | 58 +++++++++++++++++++++ packages/vscode/webpack.config.js | 8 ++- 6 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 packages/vscode/src/utils/git.worker.ts diff --git a/packages/analysis-engine/src/index.ts b/packages/analysis-engine/src/index.ts index f6de204b..a54ab75d 100644 --- a/packages/analysis-engine/src/index.ts +++ b/packages/analysis-engine/src/index.ts @@ -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); diff --git a/packages/vscode/.eslintrc.json b/packages/vscode/.eslintrc.json index 093a13f7..25d2a036 100644 --- a/packages/vscode/.eslintrc.json +++ b/packages/vscode/.eslintrc.json @@ -12,7 +12,8 @@ } ], "simple-import-sort/exports": "error", - "no-duplicate-imports": "error" + "no-duplicate-imports": "error", + "import/no-commonjs": "off" }, "overrides": [ { diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index a046b354..149b9dc4 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -7,6 +7,7 @@ import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository"; import { mapClusterNodesFrom } from "./utils/csm.mapper"; import { + fetchGitLogInParallel, findGit, getBranches, getCurrentBranchName, @@ -74,7 +75,15 @@ export async function activate(context: vscode.ExtensionContext) { const initialBaseBranchName = await fetchCurrentBranch(); const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => { - const gitLog = await getGitLog(gitPath, currentWorkspacePath); + console.time('Multi log') + const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); + console.timeEnd('Multi log') + + // console.time('Single log') + // const testGitLog = await getGitLog(gitPath, currentWorkspacePath); + // console.timeEnd('Single log') + + const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin"); const { owner, repo: initialRepo } = getRepo(gitConfig); webLoader.setGlobalOwnerAndRepo(owner, initialRepo); diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 25a4ab22..a5998c87 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -1,6 +1,10 @@ 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; @@ -154,6 +158,7 @@ export async function getGitExecutableFromPaths(paths: string[]): Promise { return new Promise((resolve, reject) => { + const args = [ "--no-pager", "log", @@ -182,6 +187,68 @@ export async function getGitLog(gitPath: string, currentWorkspacePath: string): }); } +export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise { + 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(), 10); // Buffer를 문자열로 변환 후 숫자로 변환 + resolve(commitCount); // 숫자를 반환 + } else { + reject(stderr); + } + }); + }); +} + + +export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise { + const numCores = os.cpus().length; + const numberOfThreads = Math.max(1, numCores - 1) + const totalCnt = await getLogCount(gitPath, currentWorkspacePath); + console.log("total logs", totalCnt); + const chunkSize = Math.ceil(totalCnt/ numberOfThreads); + const promises: Promise[] = []; + + for (let i = 0; i < numberOfThreads; i++) { + const skipCount = i * chunkSize; + const limitCount = chunkSize; + + console.log('__dirname:', __dirname); + 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, diff --git a/packages/vscode/src/utils/git.worker.ts b/packages/vscode/src/utils/git.worker.ts new file mode 100644 index 00000000..1d011290 --- /dev/null +++ b/packages/vscode/src/utils/git.worker.ts @@ -0,0 +1,58 @@ +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 args = [ + '--no-pager', + 'log', + '--all', + '--parents', + '--numstat', + '--date-order', + '--pretty=fuller', + '--decorate', + '-c', + `--skip=${skipCount}`, + `-n ${limitCount}`, + ]; + + + // resolveSpawnOutput( + // cp.spawn(gitPath, args, { + // cwd: currentWorkspacePath, + // env: Object.assign({}, process.env), + // }) + // ).then((values) => { + // const [status, stdout, stderr] = values; + // if (status === 0 && parentPort !== null) { + // parentPort.postMessage(stdout.toString()); + // } else { + // if (parentPort !== null) parentPort.postMessage(stderr); + // } + // }).catch(error => { + // console.error('Spawn Error:', error); + // }); + + 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(); \ No newline at end of file diff --git a/packages/vscode/webpack.config.js b/packages/vscode/webpack.config.js index 80a33728..85a4fbac 100644 --- a/packages/vscode/webpack.config.js +++ b/packages/vscode/webpack.config.js @@ -12,11 +12,15 @@ 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" + }, 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: "extension.js", + filename: "[name].js", libraryTarget: "commonjs2", }, externals: { From b8ae0a378b31dbfd2101227f7af881dd5c153113 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Mon, 9 Sep 2024 02:49:31 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20git.helper=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/utils/git.worker.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/packages/vscode/src/utils/git.worker.ts b/packages/vscode/src/utils/git.worker.ts index 1d011290..4a3f9a49 100644 --- a/packages/vscode/src/utils/git.worker.ts +++ b/packages/vscode/src/utils/git.worker.ts @@ -20,23 +20,6 @@ async function getPartialGitLog() { `-n ${limitCount}`, ]; - - // resolveSpawnOutput( - // cp.spawn(gitPath, args, { - // cwd: currentWorkspacePath, - // env: Object.assign({}, process.env), - // }) - // ).then((values) => { - // const [status, stdout, stderr] = values; - // if (status === 0 && parentPort !== null) { - // parentPort.postMessage(stdout.toString()); - // } else { - // if (parentPort !== null) parentPort.postMessage(stderr); - // } - // }).catch(error => { - // console.error('Spawn Error:', error); - // }); - resolveSpawnOutput( cp.spawn(gitPath, args, { cwd: currentWorkspacePath, From 861c2623cde3a30380e2d22c6f5372e0f9ef6748 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Sun, 29 Sep 2024 17:20:56 +0900 Subject: [PATCH 03/12] =?UTF-8?q?fix:=20package-lock.json=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef9d1a0d..971b54cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "githru-vscode-ext", - "version": "0.7.0", + "version": "0.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "githru-vscode-ext", - "version": "0.7.0", + "version": "0.7.1", "license": "MIT", "workspaces": [ "./packages/*" @@ -28248,7 +28248,7 @@ }, "packages/analysis-engine": { "name": "@githru-vscode-ext/analysis-engine", - "version": "0.7.0", + "version": "0.7.1", "license": "MIT", "dependencies": { "@octokit/core": "^4.0.4", @@ -29650,7 +29650,7 @@ }, "packages/view": { "name": "@githru-vscode-ext/view", - "version": "0.7.0", + "version": "0.7.1", "license": "MIT", "dependencies": { "@emotion/react": "^11.13.0", @@ -29748,9 +29748,9 @@ }, "packages/vscode": { "name": "githru-vscode-ext", - "version": "0.7.0", + "version": "0.7.1", "dependencies": { - "@githru-vscode-ext/analysis-engine": "^0.7.0", + "@githru-vscode-ext/analysis-engine": "^0.7.1", "@octokit/rest": "^20.0.1", "node-fetch": "^3.3.2" }, From a739c3f9023fe1edc1d2bfdbaf4a258a91878040 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Sun, 29 Sep 2024 17:54:25 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[engine]=20#713=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/extension.ts | 4 ---- packages/vscode/src/utils/git.util.ts | 3 ++- packages/vscode/webpack.config.js | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 628ec2fa..81deba09 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -81,10 +81,6 @@ export async function activate(context: vscode.ExtensionContext) { const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); console.timeEnd('Multi log') - // console.time('Single log') - // const testGitLog = await getGitLog(gitPath, currentWorkspacePath); - // console.timeEnd('Single log') - const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin"); diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index a5998c87..2a739331 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -188,6 +188,7 @@ export async function getGitLog(gitPath: string, currentWorkspacePath: string): } export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise { + const decimal = 10; return new Promise((resolve, reject) => { const args = [ "rev-list", @@ -204,7 +205,7 @@ export async function getLogCount(gitPath: string, currentWorkspacePath: string) const { code, error } = status; if (code === 0 && !error) { - const commitCount = parseInt(stdout.toString().trim(), 10); // Buffer를 문자열로 변환 후 숫자로 변환 + const commitCount = parseInt(stdout.toString().trim(), decimal); // Buffer를 문자열로 변환 후 숫자로 변환 resolve(commitCount); // 숫자를 반환 } else { reject(stderr); diff --git a/packages/vscode/webpack.config.js b/packages/vscode/webpack.config.js index 85a4fbac..1941adb0 100644 --- a/packages/vscode/webpack.config.js +++ b/packages/vscode/webpack.config.js @@ -19,7 +19,6 @@ const extensionConfig = { 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", }, From ed7ed3be56e5999816a37010372536bc0f97d7b1 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Tue, 1 Oct 2024 12:23:55 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[engine]=20=EB=B3=80=EC=88=98=EC=9D=98=20?= =?UTF-8?q?=EC=8B=A4=EC=A0=9C=20=EC=97=AD=ED=95=A0=EB=A1=9C=20=ED=91=9C?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/utils/git.util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 2a739331..c92ac484 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -188,7 +188,7 @@ export async function getGitLog(gitPath: string, currentWorkspacePath: string): } export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise { - const decimal = 10; + const BASE_10 = 10; return new Promise((resolve, reject) => { const args = [ "rev-list", @@ -205,7 +205,7 @@ export async function getLogCount(gitPath: string, currentWorkspacePath: string) const { code, error } = status; if (code === 0 && !error) { - const commitCount = parseInt(stdout.toString().trim(), decimal); // Buffer를 문자열로 변환 후 숫자로 변환 + const commitCount = parseInt(stdout.toString().trim(), BASE_10); // Buffer를 문자열로 변환 후 숫자로 변환 resolve(commitCount); // 숫자를 반환 } else { reject(stderr); From d5536b3a285a3a52f6dee4a37429e02a7e3ef950 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Tue, 1 Oct 2024 16:43:07 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[engine]=20=EB=A1=9C=EA=B7=B8=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=EC=97=90=20=EB=A7=9E=EB=8A=94=20=EC=93=B0=EB=A0=88?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/extension.ts | 6 ++++-- packages/vscode/src/utils/git.util.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 81deba09..2f913258 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -77,9 +77,11 @@ export async function activate(context: vscode.ExtensionContext) { const initialBaseBranchName = await fetchCurrentBranch(); const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => { - console.time('Multi log') + const startTime = Date.now(); const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); - console.timeEnd('Multi log') + const endTime = Date.now(); + const elapsedTime = (endTime - startTime) / 1000; + console.log(`${elapsedTime.toFixed(3)}s`); const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin"); diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index c92ac484..6787ea42 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -217,9 +217,11 @@ export async function getLogCount(gitPath: string, currentWorkspacePath: string) export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise { const numCores = os.cpus().length; - const numberOfThreads = Math.max(1, numCores - 1) + const totalCnt = await getLogCount(gitPath, currentWorkspacePath); - console.log("total logs", totalCnt); + let numberOfThreads = 1; + if(totalCnt > 1000) numberOfThreads = Math.max(numCores/2,1); + console.log("thread nums ",numberOfThreads); const chunkSize = Math.ceil(totalCnt/ numberOfThreads); const promises: Promise[] = []; From a18fb5ab620abf7b66017347cef50015ee0201e5 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Sun, 6 Oct 2024 15:04:53 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[engine]=20=EC=B5=9C=EB=8C=80=20=EC=93=B0?= =?UTF-8?q?=EB=A0=88=EB=93=9C=20=EC=88=98=203=EA=B0=9C=20=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=20=EB=B0=8F=20git=20=EB=A1=9C=EA=B7=B8=20=EC=B5=9C?= =?UTF-8?q?=EC=B4=88=20=ED=95=9C=20=EB=B2=88=EB=A7=8C=20=EB=B6=88=EB=9F=AC?= =?UTF-8?q?=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/extension.ts | 11 ++++------- packages/vscode/src/utils/git.util.ts | 8 ++++++-- packages/vscode/src/webview-loader.ts | 3 +-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 2f913258..37292670 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -53,6 +53,8 @@ export async function activate(context: vscode.ExtensionContext) { const currentWorkspacePath = normalizeFsPath(currentWorkspaceUri.fsPath); + const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); + const githubToken: string | undefined = await getGithubToken(secrets); if (!githubToken) { throw new GithubTokenUndefinedError("Cannot find your GitHub token. Retrying github authentication..."); @@ -76,14 +78,9 @@ export async function activate(context: vscode.ExtensionContext) { }; const initialBaseBranchName = await fetchCurrentBranch(); - const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => { - const startTime = Date.now(); - const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); - const endTime = Date.now(); - const elapsedTime = (endTime - startTime) / 1000; - console.log(`${elapsedTime.toFixed(3)}s`); + - + const fetchClusterNodes = async (baseBranchName = initialBaseBranchName) => { const gitConfig = await getGitConfig(gitPath, currentWorkspacePath, "origin"); const { owner, repo: initialRepo } = getRepo(gitConfig); diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 6787ea42..b4f23af0 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -217,11 +217,15 @@ export async function getLogCount(gitPath: string, currentWorkspacePath: string) export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise { const numCores = os.cpus().length; + console.log("!!!!!!!!!!!!!!!GetLog!!!!!!!!!!!"); const totalCnt = await getLogCount(gitPath, currentWorkspacePath); let numberOfThreads = 1; - if(totalCnt > 1000) numberOfThreads = Math.max(numCores/2,1); - console.log("thread nums ",numberOfThreads); + if(totalCnt > 1000){ + if(numCores < 4) numberOfThreads = 2; + else numberOfThreads = 3; + } + const chunkSize = Math.ceil(totalCnt/ numberOfThreads); const promises: Promise[] = []; diff --git a/packages/vscode/src/webview-loader.ts b/packages/vscode/src/webview-loader.ts index c7a19c65..a62ee29d 100644 --- a/packages/vscode/src/webview-loader.ts +++ b/packages/vscode/src/webview-loader.ts @@ -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( `${ANALYZE_DATA_KEY}_${baseBranchName}` ); - let analyzedData = storedAnalyzedData; + analyzedData = storedAnalyzedData; if (!storedAnalyzedData) { console.log("No cache Data"); console.log("baseBranchName : ", baseBranchName); From 7952cd05c8832ee617f757f40986216ce46d9888 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Sun, 6 Oct 2024 15:26:50 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[engine]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=A1=9C=EA=B7=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/utils/git.util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index b4f23af0..31095885 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -217,7 +217,6 @@ export async function getLogCount(gitPath: string, currentWorkspacePath: string) export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePath: string): Promise { const numCores = os.cpus().length; - console.log("!!!!!!!!!!!!!!!GetLog!!!!!!!!!!!"); const totalCnt = await getLogCount(gitPath, currentWorkspacePath); let numberOfThreads = 1; From be3931a6ffc6f00debd3a4003c3addecfd11f9ec Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Mon, 7 Oct 2024 19:22:57 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[engine]=20=EC=9E=84=EA=B3=84=20=EC=93=B0?= =?UTF-8?q?=EB=A0=88=EB=93=9C=20=EC=88=98,=20=EC=BD=94=EC=96=B4=20?= =?UTF-8?q?=EC=88=98=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/extension.ts | 4 ++-- packages/vscode/src/utils/git.util.ts | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 37292670..4e7f3bfe 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -53,8 +53,6 @@ export async function activate(context: vscode.ExtensionContext) { const currentWorkspacePath = normalizeFsPath(currentWorkspaceUri.fsPath); - const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); - const githubToken: string | undefined = await getGithubToken(secrets); if (!githubToken) { throw new GithubTokenUndefinedError("Cannot find your GitHub token. Retrying github authentication..."); @@ -62,6 +60,8 @@ export async function activate(context: vscode.ExtensionContext) { const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath); + const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); + const fetchCurrentBranch = async () => { let branchName; try { diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 31095885..0ca51e7b 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -220,10 +220,14 @@ export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePat const totalCnt = await getLogCount(gitPath, currentWorkspacePath); let numberOfThreads = 1; - if(totalCnt > 1000){ - if(numCores < 4) numberOfThreads = 2; - else numberOfThreads = 3; - } + + const taskThreshold = 1000; + const coreCountThreshold = 4; + +if (totalCnt > taskThreshold) { + if (numCores < coreCountThreshold) numberOfThreads = 2; + else numberOfThreads = 3; +} const chunkSize = Math.ceil(totalCnt/ numberOfThreads); const promises: Promise[] = []; From 4488e5d0f908ced3cec63cd9ca1ac2a733195a6b Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Mon, 7 Oct 2024 23:23:02 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[engine]=20git.worker.ts=EC=97=90=20?= =?UTF-8?q?=EC=83=88=EB=A1=9C=EC=9A=B4=20git=20format=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/extension.ts | 3 +-- packages/vscode/src/utils/git.util.ts | 2 ++ packages/vscode/src/utils/git.worker.ts | 23 +++++++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index 77ec148c..4e7f3bfe 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -60,8 +60,7 @@ export async function activate(context: vscode.ExtensionContext) { const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath); - // const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); - const gitLog = await getGitLog(gitPath, currentWorkspacePath); + const gitLog = await fetchGitLogInParallel(gitPath, currentWorkspacePath); const fetchCurrentBranch = async () => { let branchName; diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 795afb36..7a97caa6 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -259,6 +259,8 @@ if (totalCnt > taskThreshold) { currentWorkspacePath, skipCount, limitCount, + COMMIT_SEPARATOR, + GIT_LOG_SEPARATOR }, }); diff --git a/packages/vscode/src/utils/git.worker.ts b/packages/vscode/src/utils/git.worker.ts index 4a3f9a49..5540fc2a 100644 --- a/packages/vscode/src/utils/git.worker.ts +++ b/packages/vscode/src/utils/git.worker.ts @@ -3,9 +3,28 @@ import { parentPort, workerData } from 'worker_threads'; import { resolveSpawnOutput } from './git.util' -const { gitPath, currentWorkspacePath, skipCount, limitCount } = workerData; +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', @@ -13,7 +32,7 @@ async function getPartialGitLog() { '--parents', '--numstat', '--date-order', - '--pretty=fuller', + `--pretty=format:${gitLogFormat}`, '--decorate', '-c', `--skip=${skipCount}`, From 883453d99863db96c3e8e0cbb19dd6a3d4b8ec93 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Tue, 15 Oct 2024 20:46:58 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[engine]=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EB=B0=8F=20prettier=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vscode/src/utils/git.util.ts | 74 +++++++--------- packages/vscode/src/utils/git.worker.ts | 107 ++++++++++++------------ 2 files changed, 85 insertions(+), 96 deletions(-) diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index 7a97caa6..9867cc84 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -1,11 +1,9 @@ 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 os from "os"; import * as path from "path"; -import { Worker } from 'worker_threads'; - - +import { Worker } from "worker_threads"; export interface GitExecutable { readonly path: string; @@ -204,79 +202,71 @@ export async function getGitLog(gitPath: string, currentWorkspacePath: string): } export async function getLogCount(gitPath: string, currentWorkspacePath: string): Promise { - const BASE_10 = 10; - return new Promise((resolve, reject) => { - const args = [ - "rev-list", - "--count", - "--all", - ]; + 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); // 숫자를 반환 - } else { - reject(stderr); - } - }); + 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 { 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; -} - - const chunkSize = Math.ceil(totalCnt/ numberOfThreads); + if (totalCnt > taskThreshold) { + if (numCores < coreCountThreshold) numberOfThreads = 2; + else numberOfThreads = 3; + } + + const chunkSize = Math.ceil(totalCnt / numberOfThreads); const promises: Promise[] = []; for (let i = 0; i < numberOfThreads; i++) { const skipCount = i * chunkSize; const limitCount = chunkSize; - console.log('__dirname:', __dirname); - const worker = new Worker(path.resolve(__dirname, './worker.js'), { + const worker = new Worker(path.resolve(__dirname, "./worker.js"), { workerData: { gitPath, currentWorkspacePath, skipCount, limitCount, - COMMIT_SEPARATOR, - GIT_LOG_SEPARATOR + COMMIT_SEPARATOR, + GIT_LOG_SEPARATOR, }, }); promises.push( new Promise((resolve, reject) => { - worker.on('message', resolve); - worker.on('error', reject); + worker.on("message", resolve); + worker.on("error", reject); }) ); } - return Promise.all(promises).then((logs) => logs.join('\n')); + return Promise.all(promises).then((logs) => logs.join("\n")); } - - export async function getGitConfig( gitPath: string, currentWorkspacePath: string, diff --git a/packages/vscode/src/utils/git.worker.ts b/packages/vscode/src/utils/git.worker.ts index 5540fc2a..407725be 100644 --- a/packages/vscode/src/utils/git.worker.ts +++ b/packages/vscode/src/utils/git.worker.ts @@ -1,60 +1,59 @@ -import * as cp from 'child_process'; -import { parentPort, workerData } from 'worker_threads'; +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; - - +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); - }); + 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(); \ No newline at end of file +getPartialGitLog(); From fb7975a95b94c04956fe2d4bc7aba2cb8b570493 Mon Sep 17 00:00:00 2001 From: YongHyunKing Date: Tue, 22 Oct 2024 19:17:13 +0900 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B9=8C=EB=93=9C=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 2 -- packages/vscode/src/utils/git.util.ts | 2 -- packages/vscode/src/utils/git.worker.ts | 16 ++++++++-------- packages/vscode/src/webview-loader.ts | 6 ++---- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index b00c2080..424e5f31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28234,7 +28234,6 @@ "packages/analysis-engine": { "name": "@githru-vscode-ext/analysis-engine", "version": "0.7.2", - "version": "0.7.1", "license": "MIT", "dependencies": { "@octokit/core": "^4.0.4", @@ -29637,7 +29636,6 @@ "packages/view": { "name": "@githru-vscode-ext/view", "version": "0.7.2", - "version": "0.7.1", "license": "MIT", "dependencies": { "@emotion/react": "^11.13.0", diff --git a/packages/vscode/src/utils/git.util.ts b/packages/vscode/src/utils/git.util.ts index f64e3017..e77bd9c0 100644 --- a/packages/vscode/src/utils/git.util.ts +++ b/packages/vscode/src/utils/git.util.ts @@ -249,8 +249,6 @@ export async function fetchGitLogInParallel(gitPath: string, currentWorkspacePat currentWorkspacePath, skipCount, limitCount, - COMMIT_SEPARATOR, - GIT_LOG_SEPARATOR, }, }); diff --git a/packages/vscode/src/utils/git.worker.ts b/packages/vscode/src/utils/git.worker.ts index 407725be..f5c9da26 100644 --- a/packages/vscode/src/utils/git.worker.ts +++ b/packages/vscode/src/utils/git.worker.ts @@ -3,11 +3,11 @@ import { parentPort, workerData } from "worker_threads"; import { resolveSpawnOutput } from "./git.util"; -const { gitPath, currentWorkspacePath, skipCount, limitCount, COMMIT_SEPARATOR, GIT_LOG_SEPARATOR } = workerData; +const { gitPath, currentWorkspacePath, skipCount, limitCount } = workerData; async function getPartialGitLog() { const gitLogFormat = - COMMIT_SEPARATOR + + "%n%n" + [ "%H", // commit hash (id) "%P", // parent hashes @@ -15,12 +15,12 @@ async function getPartialGitLog() { "%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; + "%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", diff --git a/packages/vscode/src/webview-loader.ts b/packages/vscode/src/webview-loader.ts index 68ad7e45..73c9ecf6 100644 --- a/packages/vscode/src/webview-loader.ts +++ b/packages/vscode/src/webview-loader.ts @@ -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); @@ -50,7 +49,6 @@ export default class WebviewLoader implements vscode.Disposable { 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); @@ -75,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, });