diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java index 986d71b..c3a2d9f 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/DiscussionRepository.java @@ -1,8 +1,6 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import java.util.List; import java.util.Optional; @@ -24,7 +22,7 @@ public interface DiscussionRepository { void deleteById(String discussionId); - Page findAll(Pageable pagination); + List findAll(); List findAllById(Set discussionIds); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java index 921520b..68ddb29 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java @@ -16,14 +16,11 @@ public interface MergeRequestRepository { Set findAllIdByStateIn(@NonNull Set states); - //TODO [28.01.2022]: Решить, нужно ли оставить - List findAllByAssignee(@NonNull Long userId); - MergeRequest save(MergeRequest mergeRequest); Optional findById(Long mergeRequestId); - Page findAll(Pageable pagination); + List findAll(); List findAllById(Set mergeRequestIds); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java index 4765d15..c666359 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java @@ -3,8 +3,6 @@ package dev.struchkov.bot.gitlab.context.service; import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import lombok.NonNull; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import java.util.List; import java.util.Set; @@ -37,7 +35,7 @@ public interface DiscussionService { List createAll(@NonNull List newDiscussions); - Page getAll(@NonNull Pageable pagination); + List getAll(); void deleteById(String discussionId); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java index bc44bf0..4433695 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java @@ -28,7 +28,7 @@ public interface MergeRequestsService { */ Set getAllId(Set statuses); - Page getAll(Pageable pagination); + List getAll(); Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java index 11d6be2..14747d2 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java @@ -23,8 +23,6 @@ import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -297,8 +295,8 @@ public class DiscussionServiceImpl implements DiscussionService { } @Override - public Page getAll(@NonNull Pageable pagination) { - return repository.findAll(pagination); + public List getAll() { + return repository.findAll(); } @Override diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index a9b6007..a98c363 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -210,8 +210,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { } @Override - public Page getAll(Pageable pagination) { - return repository.findAll(pagination); + public List getAll() { + return repository.findAll(); } @Override diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java index 882710e..c41bf38 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java @@ -14,8 +14,6 @@ import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.core.convert.ConversionService; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Component; import java.text.MessageFormat; @@ -45,8 +43,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; @RequiredArgsConstructor public class DiscussionParser { - public static final int COUNT = 500; - private final DiscussionService discussionService; private final MergeRequestsService mergeRequestsService; private final ConversionService conversionService; @@ -59,18 +55,12 @@ public class DiscussionParser { */ public void scanNewDiscussion() { log.debug("Старт обработки новых дискуссий"); - int page = 0; - Page mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT)); + final List mergeRequests = mergeRequestsService.getAll(); - while (mergeRequestSheet.hasContent()) { - final List mergeRequests = mergeRequestSheet.getContent(); - - for (MergeRequest mergeRequest : mergeRequests) { - processingMergeRequest(mergeRequest); - } - - mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT)); + for (MergeRequest mergeRequest : mergeRequests) { + processingMergeRequest(mergeRequest); } + log.debug("Конец обработки новых дискуссий"); } @@ -156,38 +146,32 @@ public class DiscussionParser { */ public void scanOldDiscussions() { log.debug("Старт обработки старых дискуссий"); - int page = 0; - Page discussionPage = discussionService.getAll(PageRequest.of(page, COUNT)); + final List discussions = discussionService.getAll(); - while (discussionPage.hasContent()) { - final List discussions = discussionPage.getContent(); + // Удаляем обсуждения, которые потеряли свои MR + //TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия + discussions.stream() + .filter(discussion -> checkNull(discussion.getMergeRequest())) + .map(Discussion::getId) + .forEach(discussionService::deleteById); - // Удаляем обсуждения, которые потеряли свои MR - //TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия - discussions.stream() - .filter(discussion -> checkNull(discussion.getMergeRequest())) - .map(Discussion::getId) - .forEach(discussionService::deleteById); - - final List newDiscussions = new ArrayList<>(); - for (Discussion discussion : discussions) { - if (checkNotNull(discussion.getMergeRequest())) { - getOldDiscussionJson(discussion) - .map(json -> { - final Discussion newDiscussion = conversionService.convert(json, Discussion.class); - newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest())); - return newDiscussion; - }).ifPresent(newDiscussions::add); - } + final List newDiscussions = new ArrayList<>(); + for (Discussion discussion : discussions) { + if (checkNotNull(discussion.getMergeRequest())) { + getOldDiscussionJson(discussion) + .map(json -> { + final Discussion newDiscussion = conversionService.convert(json, Discussion.class); + newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest())); + return newDiscussion; + }).ifPresent(newDiscussions::add); } - - if (checkNotEmpty(newDiscussions)) { - personMapping(newDiscussions); - discussionService.updateAll(newDiscussions); - } - - discussionPage = discussionService.getAll(PageRequest.of(++page, COUNT)); } + + if (checkNotEmpty(newDiscussions)) { + personMapping(newDiscussions); + discussionService.updateAll(newDiscussions); + } + log.debug("Конец обработки старых дискуссий"); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java index 84afd61..a3141df 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java @@ -48,7 +48,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; @Service public class PipelineParser { - public static final Integer COUNT = 100; private static final Set oldStatus = Set.of( CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL ); diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java index 2782985..3bd1430 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/DiscussionRepositoryImpl.java @@ -6,8 +6,6 @@ import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; @@ -45,8 +43,8 @@ public class DiscussionRepositoryImpl implements DiscussionRepository { } @Override - public Page findAll(Pageable pagination) { - return jpaRepository.findAll(pagination); + public List findAll() { + return jpaRepository.findAll(); } @Override diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java index 41473da..9324d6e 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java @@ -28,11 +28,6 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository { return jpaRepository.findAllIdByStateIn(statuses); } - @Override - public List findAllByAssignee(@NonNull Long userId) { - return jpaRepository.findAllByAssigneeId(userId); - } - @Override public MergeRequest save(MergeRequest mergeRequest) { return jpaRepository.save(mergeRequest); @@ -44,8 +39,8 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository { } @Override - public Page findAll(Pageable pagination) { - return jpaRepository.findAll(pagination); + public List findAll() { + return jpaRepository.findAll(); } @Override