#27 -- add multithreading
This commit is contained in:
parent
ccde75abc6
commit
9ab0d9cee0
@ -45,6 +45,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@ -59,6 +60,7 @@ public class GitRepositoryService {
|
|||||||
@Value("${extractor.custom-projects-dir}")
|
@Value("${extractor.custom-projects-dir}")
|
||||||
private String customProjectsDir;
|
private String customProjectsDir;
|
||||||
private final ExecutorService executorService = Executors.newFixedThreadPool(4);
|
private final ExecutorService executorService = Executors.newFixedThreadPool(4);
|
||||||
|
private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(4);
|
||||||
|
|
||||||
private final StructuralUnitService structuralUnitService;
|
private final StructuralUnitService structuralUnitService;
|
||||||
|
|
||||||
@ -109,22 +111,34 @@ public class GitRepositoryService {
|
|||||||
List<RevCommit> commits = new ArrayList<>();
|
List<RevCommit> commits = new ArrayList<>();
|
||||||
git.log().setSkip(commitsFrom).setMaxCount(commitsTo - commitsFrom).call().forEach(commits::add);
|
git.log().setSkip(commitsFrom).setMaxCount(commitsTo - commitsFrom).call().forEach(commits::add);
|
||||||
|
|
||||||
List<Commit> list = new ArrayList<>();
|
List<Commit> list = new CopyOnWriteArrayList<>();
|
||||||
RevCommit prevCommit = null;
|
RevCommit prevCommit = null;
|
||||||
LOG.debug("Start analyse {} commits", commits.size());
|
LOG.debug("Start analyse {} commits", commits.size());
|
||||||
LOG.debug(" {} to {} commits", commitsFrom, commitsTo);
|
LOG.debug(" {} to {} commits", commitsFrom, commitsTo);
|
||||||
|
List<Future<Commit>> futureCommits = new ArrayList<>();
|
||||||
for (RevCommit revCommit : commits) {
|
for (RevCommit revCommit : commits) {
|
||||||
|
final RevCommit forPrevCommit = prevCommit;
|
||||||
|
futureCommits.add(executorServiceCommits.submit(() -> {
|
||||||
Commit commit = new Commit(
|
Commit commit = new Commit(
|
||||||
revCommit.getFullMessage(),
|
revCommit.getFullMessage(),
|
||||||
new Author(revCommit.getAuthorIdent().getName()),
|
new Author(revCommit.getAuthorIdent().getName()),
|
||||||
Date.from(Instant.ofEpochSecond(revCommit.getCommitTime())),
|
Date.from(Instant.ofEpochSecond(revCommit.getCommitTime())),
|
||||||
revCommit.getName());
|
revCommit.getName());
|
||||||
if (prevCommit != null) {
|
if (forPrevCommit != null) {
|
||||||
commit.setFileChanges(findDiffBetweenTwoRevisions(revCommit, prevCommit, localRepo));
|
commit.setFileChanges(findDiffBetweenTwoRevisions(revCommit, forPrevCommit, localRepo));
|
||||||
}
|
}
|
||||||
list.add(commit);
|
list.add(commit);
|
||||||
|
return commit;
|
||||||
|
}));
|
||||||
prevCommit = revCommit;
|
prevCommit = revCommit;
|
||||||
}
|
}
|
||||||
|
futureCommits.forEach(fc -> {
|
||||||
|
try {
|
||||||
|
fc.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
git.close();
|
git.close();
|
||||||
localRepo.close();
|
localRepo.close();
|
||||||
return list;
|
return list;
|
||||||
|
Loading…
Reference in New Issue
Block a user