Skip to content

Commit 4aa08f2

Browse files
#172 Removed caching in ChangePronenessRanker
Removed caching in ChangePronenessRanker - there was no discernible difference. Removing it will reduce memory use.
1 parent 8a2abbf commit 4aa08f2

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

change-proneness-ranker/src/main/java/org/hjug/git/ChangePronenessRanker.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,25 @@
88
@Slf4j
99
public class ChangePronenessRanker {
1010

11-
private final Map<Integer, Integer> changeCountsByTimeStamps = new HashMap<>();
11+
private final TreeMap<Integer, Integer> changeCountsByTimeStamps = new TreeMap<>();
1212
private final Map<String, ScmLogInfo> cachedScmLogInfos = new HashMap<>();
1313

1414
public ChangePronenessRanker(GitLogReader repositoryLogReader) {
1515
try {
1616
log.info("Capturing change count based on commit timestamps");
17-
changeCountsByTimeStamps.putAll(
18-
computeChangeCountsByTimeStamps(repositoryLogReader.captureChangeCountByCommitTimestamp()));
17+
changeCountsByTimeStamps.putAll(repositoryLogReader.captureChangeCountByCommitTimestamp());
1918
} catch (IOException | GitAPIException e) {
2019
log.error("Error reading from repository: {}", e.getMessage());
2120
}
2221
}
2322

24-
private Map<Integer, Integer> computeChangeCountsByTimeStamps(TreeMap<Integer, Integer> commitsWithChangeCounts) {
25-
HashMap<Integer, Integer> changeCountsByTimeStamps = new HashMap<>();
26-
int runningTotal = 0;
27-
for (Map.Entry<Integer, Integer> commitChangeCountEntry :
28-
commitsWithChangeCounts.descendingMap().entrySet()) {
29-
runningTotal += commitChangeCountEntry.getValue();
30-
changeCountsByTimeStamps.put(commitChangeCountEntry.getKey(), runningTotal);
31-
}
32-
33-
return changeCountsByTimeStamps;
34-
}
35-
3623
public void rankChangeProneness(List<ScmLogInfo> scmLogInfos) {
3724
for (ScmLogInfo scmLogInfo : scmLogInfos) {
3825
if (!cachedScmLogInfos.containsKey(scmLogInfo.getPath())) {
39-
if (scmLogInfo.getEarliestCommit() == 0) {
40-
log.warn("No commits found for {}", scmLogInfo.getPath());
41-
continue;
42-
}
43-
44-
int commitsInRepositorySinceCreation = changeCountsByTimeStamps.get(scmLogInfo.getEarliestCommit());
26+
int commitsInRepositorySinceCreation =
27+
changeCountsByTimeStamps.tailMap(scmLogInfo.getEarliestCommit()).values().stream()
28+
.mapToInt(i -> i)
29+
.sum();
4530

4631
scmLogInfo.setChangeProneness((float) scmLogInfo.getCommitCount() / commitsInRepositorySinceCreation);
4732
cachedScmLogInfos.put(scmLogInfo.getPath(), scmLogInfo);

0 commit comments

Comments
 (0)