#27 -- fix performance

This commit is contained in:
Anton Romanov 2021-04-30 10:11:20 +04:00
parent 49e906c190
commit ccde75abc6
2 changed files with 23 additions and 16 deletions

View File

@ -41,61 +41,58 @@ public class StatisticController {
.map(tc -> tc[0].toString().substring(tc[0].toString().lastIndexOf("/") + 1)) .map(tc -> tc[0].toString().substring(tc[0].toString().lastIndexOf("/") + 1))
.collect(Collectors.toList()); .collect(Collectors.toList());
model.addAttribute("urls", urls); model.addAttribute("urls", urls);
model.addAttribute("commitEntityData", entityCommits()); model.addAttribute("commitEntityData", getEntityCommits());
model.addAttribute("commitTimeEntityData", allTimeEntityCommits()); model.addAttribute("commitTimeEntityData", allTimeEntityCommits());
return STATISTIC; return STATISTIC;
} }
public List<Object[]> authorCommits() { public List<Object[]> authorCommits() {
List<Object[]> authorCommits = commitRepository.getCommitAuthorStatistic().stream() return commitRepository.getCommitAuthorStatistic().stream()
.map(stat -> new Object[]{stat.getAuthor(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getAuthor(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
return authorCommits;
} }
public List<Object[]> getUrlCommits() { public List<Object[]> getUrlCommits() {
List<Object[]> urlCommits = commitRepository.getCommitUrlStatistic().stream() return commitRepository.getCommitUrlStatistic().stream()
.map(stat -> new Object[]{stat.getUrl(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getUrl(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
return urlCommits;
} }
public List<Object[]> getTimeCommits() { public List<Object[]> getTimeCommits() {
List<Object[]> timeCommits = commitRepository.getCommitTimeStatistic().stream() return commitRepository.getCommitTimeStatistic().stream()
.map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
return timeCommits;
} }
public List<Object[]> entityCommits() { public List<Object[]> getEntityCommits() {
List<Object[]> entityCommits = commitRepository.getCommitEntityStatistic().stream() List<Object[]> entityCommits = commitRepository.getCommitEntityStatistic().stream()
.map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
for (int i = 0; i < entityCommits.size(); i++) { for (Object[] entityCommit : entityCommits) {
entityCommits.get(i)[0] = Boolean.TRUE.equals(entityCommits.get(i)[0]) entityCommit[0] = Boolean.TRUE.equals(entityCommit[0])
? "Есть сущности" ? "Есть сущности"
: (entityCommits.get(i)[0] == null : (entityCommit[0] == null
? "Нет данных" ? "Нет данных"
: "Нет сущностей"); : "Нет сущностей");
} }
return entityCommits; return entityCommits;
} }
public List<Object[]> timeEntityCommits() { public List<Object[]> getTimeEntityCommits() {
List<Object[]> timeEntityCommits = commitRepository.getCommitTimeEntityStatistic().stream() return commitRepository.getCommitTimeEntityStatistic().stream()
.map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
return timeEntityCommits;
} }
public List<Object[]> allTimeEntityCommits() { public List<Object[]> allTimeEntityCommits() {
List<Object[]> timeEntityCommits = getTimeEntityCommits();
List<Object[]> allTimeEntityCommits = commitRepository.getCommitTimeStatistic().stream() List<Object[]> allTimeEntityCommits = commitRepository.getCommitTimeStatistic().stream()
.map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()})
.collect(Collectors.toList()); .collect(Collectors.toList());
int j = 0; int j = 0;
for (int i = 0; i < allTimeEntityCommits.size(); i++) { for (int i = 0; i < allTimeEntityCommits.size(); i++) {
if ((j < timeEntityCommits().size()) && (allTimeEntityCommits.get(i)[0].equals(timeEntityCommits().get(j)[0]))) { if ((j < timeEntityCommits.size()) && (allTimeEntityCommits.get(i)[0].equals(timeEntityCommits.get(j)[0]))) {
allTimeEntityCommits.get(i)[1] = timeEntityCommits().get(j)[1]; allTimeEntityCommits.get(i)[1] = timeEntityCommits.get(j)[1];
j++; j++;
} else { } else {
if (i > 0) { if (i > 0) {

View File

@ -54,4 +54,14 @@
referencedTableName="branch" referencedColumnNames="id" onDelete="CASCADE" referencedTableName="branch" referencedColumnNames="id" onDelete="CASCADE"
onUpdate="CASCADE"/> onUpdate="CASCADE"/>
</changeSet> </changeSet>
<changeSet author="orion" id="20210430-100000-1">
<sql>
CREATE INDEX commit_branch_idx ON public.commit
USING hash (branch_id);
CREATE INDEX file_change_commit_idx ON public.file_change
USING hash (commit_id);
CREATE INDEX line_change_file_change_idx ON public.line_change
USING hash (file_change_id);
</sql>
</changeSet>
</databaseChangeLog> </databaseChangeLog>