Skip to content

Commit

Permalink
perf: cache changed files by commit hash
Browse files Browse the repository at this point in the history
  • Loading branch information
psm14 committed Sep 14, 2024
1 parent 1a7786a commit 6deab17
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ function filterCommits({ commits, logger }, path) {
});
}

const CHANGED_FILES_MEMO = new Map();

function getChangedFiles(commitHash) {
if (CHANGED_FILES_MEMO.has(commitHash)) {
return CHANGED_FILES_MEMO.get(commitHash);
}

try {
const result = execSync(
`git diff-tree --no-commit-id --name-only -r ${commitHash}`,
{ encoding: "utf-8" }
);
return result.trim().split("\n");
const changedFiles = result.trim().split("\n");
CHANGED_FILES_MEMO.set(commitHash, changedFiles);
return changedFiles;
} catch (error) {
logger.error(
`Error getting changed files for commit ${commitHash}:`,
Expand Down

0 comments on commit 6deab17

Please sign in to comment.