WIP: страницы для правил #62

Closed
Ghost wants to merge 132 commits from master into 61-rules-pages
3 changed files with 6 additions and 13 deletions
Showing only changes of commit d72cf99fa6 - Show all commits

View File

@ -41,6 +41,7 @@ public class BranchService {
@Transactional @Transactional
public Branch save(Branch branch, List<Commit> commits) { public Branch save(Branch branch, List<Commit> commits) {
LOG.debug("Start save {} branch with {} commits ", branch.getName(), commits.size()); LOG.debug("Start save {} branch with {} commits ", branch.getName(), commits.size());
LOG.debug("Current branch contains {} commits ", branch.getCommits().size());
List<Integer> commitsToRemoveIds = branch.getCommits().stream().map(BaseEntity::getId).collect(Collectors.toList()); List<Integer> commitsToRemoveIds = branch.getCommits().stream().map(BaseEntity::getId).collect(Collectors.toList());
branch.setCommits(commitService.save(commits)); branch.setCommits(commitService.save(commits));
LOG.debug("Save branch {} ", branch.getName()); LOG.debug("Save branch {} ", branch.getName());
@ -50,12 +51,12 @@ public class BranchService {
return branch; return branch;
} }
@Transactional
public Branch addCommits(Branch branch, List<Commit> commits) { public Branch addCommits(Branch branch, List<Commit> commits) {
LOG.debug("Start add commits to {} branch with {} commits ", branch.getName(), commits.size()); LOG.debug("Start add commits to {} branch with {} commits ", branch.getName(), commits.size());
commitService.save(commits); branch.getCommits().addAll(commitService.save(commits));
LOG.debug("Save branch {} ", branch.getName()); LOG.debug("Save branch {} ", branch.getName());
commitService.updateBranchId(commits, branch.getId()); return save(branch);
return branch;
} }
public Branch findByRepositoryAndName(GitRepository gitRepository, String branchName) { public Branch findByRepositoryAndName(GitRepository gitRepository, String branchName) {

View File

@ -44,14 +44,6 @@ public class CommitService {
jdbcTemplate.update("DELETE FROM commit where branch_id is null"); jdbcTemplate.update("DELETE FROM commit where branch_id is null");
} }
public void updateBranchId(List<Commit> commits, Integer branchId) {
List<String> commitIds = commits.stream().map(c -> c.getId().toString()).collect(Collectors.toList());
String updateQuery = "update commit set branch_id = ? where id in (%s)";
updateQuery = String.format(updateQuery, String.join(",", commitIds));
jdbcTemplate.update(updateQuery, branchId);
}
public List<Commit> findByRepositoryIdAndName(Integer repositoryId, String branchName) { public List<Commit> findByRepositoryIdAndName(Integer repositoryId, String branchName) {
return commitRepository.findByRepositoryIdAndBranchName(repositoryId, branchName); return commitRepository.findByRepositoryIdAndBranchName(repositoryId, branchName);
} }

View File

@ -74,9 +74,9 @@ public class IndexService {
commitsTo += COMMITS_PAGE_SIZE; commitsTo += COMMITS_PAGE_SIZE;
commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false);
} }
final Branch branchForSave = branch; branch = branchService.findByBranchId(branch.getId()).orElseThrow(() -> new RuntimeException("Branch not found by id"));
final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED);
timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave));
branchService.updateStatus(branch, IndexingStatus.FINISHED);
LOG.debug("Complete indexing {} branch", branch.getName()); LOG.debug("Complete indexing {} branch", branch.getName());
} }