Merge branch '27-logs' into 'master'
Resolve "Добавить логирование всех действий по индексации" Closes #27 See merge request romanov73/git-extractor!26
This commit is contained in:
commit
743e730397
@ -40,9 +40,11 @@ public class RepoController {
|
|||||||
@GetMapping("commits")
|
@GetMapping("commits")
|
||||||
public List<Commit> getCommits(@RequestParam("repositoryUrl") String repositoryUrl,
|
public List<Commit> getCommits(@RequestParam("repositoryUrl") String repositoryUrl,
|
||||||
@RequestParam("branchName") String branchName,
|
@RequestParam("branchName") String branchName,
|
||||||
|
int commitsFrom,
|
||||||
|
int commitsTo,
|
||||||
HttpServletRequest request) throws GitAPIException, IOException {
|
HttpServletRequest request) throws GitAPIException, IOException {
|
||||||
LOG.debug("Get commits {} {}. User ip {}", repositoryUrl, branchName, HttpUtils.getUserIp(request));
|
LOG.debug("Get commits {} {}. User ip {}", repositoryUrl, branchName, HttpUtils.getUserIp(request));
|
||||||
return gitRepositoryService.getCommits(repositoryUrl, branchName);
|
return gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("index")
|
@GetMapping("index")
|
||||||
|
@ -20,7 +20,7 @@ import ru.ulstu.extractor.model.Repository;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
||||||
@Query("SELECT DISTINCT c FROM Commit c JOIN c.branch b JOIN c.fileChanges f JOIN c.author a JOIN b.repository r WHERE r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)")
|
@Query("SELECT DISTINCT c FROM Commit c LEFT JOIN c.branch b LEFT JOIN c.fileChanges f LEFT JOIN c.author a LEFT JOIN b.repository r WHERE r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)")
|
||||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity);
|
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity);
|
||||||
|
|
||||||
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
|
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
|
||||||
|
@ -40,6 +40,14 @@ public class BranchService {
|
|||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Branch addCommits(Branch branch, List<Commit> commits) {
|
||||||
|
LOG.debug("Start add commits to {} branch with {} commits ", branch.getName(), commits.size());
|
||||||
|
branch.getCommits().addAll(commitService.save(commits));
|
||||||
|
LOG.debug("Save branch {} ", branch.getName());
|
||||||
|
branch = branchRepository.save(branch);
|
||||||
|
return branch;
|
||||||
|
}
|
||||||
|
|
||||||
public Branch findByRepositoryAndName(Repository repository, String branchName) {
|
public Branch findByRepositoryAndName(Repository repository, String branchName) {
|
||||||
return branchRepository.findByRepositoryAndName(repository, branchName);
|
return branchRepository.findByRepositoryAndName(repository, branchName);
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,10 @@
|
|||||||
|
|
||||||
package ru.ulstu.extractor.service;
|
package ru.ulstu.extractor.service;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.repository.CommitRepository;
|
import ru.ulstu.extractor.repository.CommitRepository;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -33,21 +26,6 @@ public class CommitService {
|
|||||||
this.authorService = authorService;
|
this.authorService = authorService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Commit> findPaginated(Pageable pageable, String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
||||||
int pageSize = pageable.getPageSize();
|
|
||||||
int currentPage = pageable.getPageNumber();
|
|
||||||
int startItem = currentPage * pageSize;
|
|
||||||
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
|
|
||||||
|
|
||||||
if (commits.size() < startItem) {
|
|
||||||
commits = Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
int toIndex = Math.min(startItem + pageSize, commits.size());
|
|
||||||
commits = commits.subList(startItem, toIndex);
|
|
||||||
}
|
|
||||||
return new PageImpl<>(commits, PageRequest.of(currentPage, pageSize), commits.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(List<Commit> commitsToRemove) {
|
public void delete(List<Commit> commitsToRemove) {
|
||||||
commitRepository.deleteAll(commitsToRemove);
|
commitRepository.deleteAll(commitsToRemove);
|
||||||
}
|
}
|
||||||
|
@ -98,9 +98,11 @@ public class GitRepositoryService {
|
|||||||
return branches;
|
return branches;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Commit> getCommits(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
public List<Commit> getCommits(String repositoryUrl, String branchName, int commitsFrom, int commitsTo, boolean needUpdate) throws GitAPIException, IOException {
|
||||||
LOG.debug("Get commits of {}. Branch {}", repositoryUrl, branchName);
|
LOG.debug("Get commits of {}. Branch {}", repositoryUrl, branchName);
|
||||||
|
if (needUpdate) {
|
||||||
cloneOrUpdateRepo(repositoryUrl, branchName);
|
cloneOrUpdateRepo(repositoryUrl, branchName);
|
||||||
|
}
|
||||||
Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
||||||
Git git = new Git(localRepo);
|
Git git = new Git(localRepo);
|
||||||
|
|
||||||
@ -110,9 +112,12 @@ public class GitRepositoryService {
|
|||||||
List<Commit> list = new ArrayList<>();
|
List<Commit> list = new ArrayList<>();
|
||||||
RevCommit prevCommit = null;
|
RevCommit prevCommit = null;
|
||||||
LOG.debug("Start analyse {} commits", commits.size());
|
LOG.debug("Start analyse {} commits", commits.size());
|
||||||
int counter = commits.size();
|
commitsFrom = Math.max(commitsFrom, 0);
|
||||||
for (RevCommit revCommit : commits) {
|
commitsTo = Math.min(commitsTo, commits.size());
|
||||||
LOG.debug(" {} of {} commits", counter--, commits.size());
|
commitsTo = Math.max(commitsTo, 0);
|
||||||
|
for (int i = commitsFrom; i < commitsTo; i++) {
|
||||||
|
RevCommit revCommit = commits.get(i);
|
||||||
|
LOG.debug(" {} to {} commits", i, commitsTo);
|
||||||
Commit commit = new Commit(
|
Commit commit = new Commit(
|
||||||
revCommit.getFullMessage(),
|
revCommit.getFullMessage(),
|
||||||
new Author(revCommit.getAuthorIdent().getName()),
|
new Author(revCommit.getAuthorIdent().getName()),
|
||||||
@ -229,7 +234,7 @@ public class GitRepositoryService {
|
|||||||
if (laterCommit == null || earlierCommit == null) {
|
if (laterCommit == null || earlierCommit == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String output = null;
|
String output;
|
||||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
DiffFormatter diffFormatter = new DiffFormatter(out);
|
DiffFormatter diffFormatter = new DiffFormatter(out);
|
||||||
diffFormatter.setRepository(localRepo);
|
diffFormatter.setRepository(localRepo);
|
||||||
@ -252,13 +257,8 @@ public class GitRepositoryService {
|
|||||||
if (maybeFileName.isPresent()) {
|
if (maybeFileName.isPresent()) {
|
||||||
fileChange = new FileChange();
|
fileChange = new FileChange();
|
||||||
fileChange.setFile(maybeFileName.get());
|
fileChange.setFile(maybeFileName.get());
|
||||||
Future<Boolean> futureEntity = executorService.submit(() -> {
|
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())));
|
||||||
return structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get()));
|
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())));
|
||||||
});
|
|
||||||
|
|
||||||
Future<Boolean> futureBL = executorService.submit(() -> {
|
|
||||||
return structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get()));
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
fileChange.setContainsBusinessLogic(futureBL.get());
|
fileChange.setContainsBusinessLogic(futureBL.get());
|
||||||
fileChange.setContainsEntity(futureEntity.get());
|
fileChange.setContainsEntity(futureEntity.get());
|
||||||
|
@ -17,11 +17,13 @@ import ru.ulstu.extractor.model.Repository;
|
|||||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class IndexService {
|
public class IndexService {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(IndexService.class);
|
private final static Logger LOG = LoggerFactory.getLogger(IndexService.class);
|
||||||
|
private final static int COMMITS_PAGE_SIZE = 10;
|
||||||
private final GitRepositoryService gitRepositoryService;
|
private final GitRepositoryService gitRepositoryService;
|
||||||
private final RepositoryRepository repositoryRepository;
|
private final RepositoryRepository repositoryRepository;
|
||||||
private final BranchService branchService;
|
private final BranchService branchService;
|
||||||
@ -44,9 +46,18 @@ public class IndexService {
|
|||||||
if (branch == null) {
|
if (branch == null) {
|
||||||
branch = new Branch(repository, branchName);
|
branch = new Branch(repository, branchName);
|
||||||
}
|
}
|
||||||
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
|
branchService.save(branch, Collections.emptyList());
|
||||||
|
int commitsFrom = 0;
|
||||||
|
int commitsTo = COMMITS_PAGE_SIZE;
|
||||||
|
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, true);
|
||||||
|
while (!commits.isEmpty()) {
|
||||||
LOG.debug("{} commits loaded.", commits.size());
|
LOG.debug("{} commits loaded.", commits.size());
|
||||||
branchService.save(branch, commits);
|
branch = branchService.addCommits(branch, commits);
|
||||||
LOG.debug("{} commits successfully saved. {} {}", commits.size(), repositoryUrl, branchName);
|
LOG.debug("{} commits successfully saved. {} {}", commits.size(), repositoryUrl, branchName);
|
||||||
|
commitsFrom += COMMITS_PAGE_SIZE;
|
||||||
|
commitsTo += COMMITS_PAGE_SIZE;
|
||||||
|
commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false);
|
||||||
|
}
|
||||||
|
LOG.debug("Complete indexing {} branch", branchName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user