Упростил обработку MR и тредов

This commit is contained in:
Struchkov Mark 2022-12-20 20:04:17 +03:00
parent 422de73854
commit e02187d9c1
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
10 changed files with 38 additions and 71 deletions

View File

@ -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<Discussion> findAll(Pageable pagination);
List<Discussion> findAll();
List<Discussion> findAllById(Set<String> discussionIds);

View File

@ -16,14 +16,11 @@ public interface MergeRequestRepository {
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
//TODO [28.01.2022]: Решить, нужно ли оставить
List<MergeRequest> findAllByAssignee(@NonNull Long userId);
MergeRequest save(MergeRequest mergeRequest);
Optional<MergeRequest> findById(Long mergeRequestId);
Page<MergeRequest> findAll(Pageable pagination);
List<MergeRequest> findAll();
List<MergeRequest> findAllById(Set<Long> mergeRequestIds);

View File

@ -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<Discussion> createAll(@NonNull List<Discussion> newDiscussions);
Page<Discussion> getAll(@NonNull Pageable pagination);
List<Discussion> getAll();
void deleteById(String discussionId);

View File

@ -28,7 +28,7 @@ public interface MergeRequestsService {
*/
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
Page<MergeRequest> getAll(Pageable pagination);
List<MergeRequest> getAll();
Page<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pageable pagination);

View File

@ -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<Discussion> getAll(@NonNull Pageable pagination) {
return repository.findAll(pagination);
public List<Discussion> getAll() {
return repository.findAll();
}
@Override

View File

@ -210,8 +210,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
}
@Override
public Page<MergeRequest> getAll(Pageable pagination) {
return repository.findAll(pagination);
public List<MergeRequest> getAll() {
return repository.findAll();
}
@Override

View File

@ -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<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) {
final List<MergeRequest> mergeRequests = mergeRequestSheet.getContent();
final List<MergeRequest> mergeRequests = mergeRequestsService.getAll();
for (MergeRequest mergeRequest : mergeRequests) {
processingMergeRequest(mergeRequest);
}
mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT));
}
log.debug("Конец обработки новых дискуссий");
}
@ -156,11 +146,7 @@ public class DiscussionParser {
*/
public void scanOldDiscussions() {
log.debug("Старт обработки старых дискуссий");
int page = 0;
Page<Discussion> discussionPage = discussionService.getAll(PageRequest.of(page, COUNT));
while (discussionPage.hasContent()) {
final List<Discussion> discussions = discussionPage.getContent();
final List<Discussion> discussions = discussionService.getAll();
// Удаляем обсуждения, которые потеряли свои MR
//TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия
@ -186,8 +172,6 @@ public class DiscussionParser {
discussionService.updateAll(newDiscussions);
}
discussionPage = discussionService.getAll(PageRequest.of(++page, COUNT));
}
log.debug("Конец обработки старых дискуссий");
}

View File

@ -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<PipelineStatus> oldStatus = Set.of(
CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL
);

View File

@ -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<Discussion> findAll(Pageable pagination) {
return jpaRepository.findAll(pagination);
public List<Discussion> findAll() {
return jpaRepository.findAll();
}
@Override

View File

@ -28,11 +28,6 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
return jpaRepository.findAllIdByStateIn(statuses);
}
@Override
public List<MergeRequest> 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<MergeRequest> findAll(Pageable pagination) {
return jpaRepository.findAll(pagination);
public List<MergeRequest> findAll() {
return jpaRepository.findAll();
}
@Override