Упростил обработку 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; package dev.struchkov.bot.gitlab.context.repository;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; 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.List;
import java.util.Optional; import java.util.Optional;
@ -24,7 +22,7 @@ public interface DiscussionRepository {
void deleteById(String discussionId); void deleteById(String discussionId);
Page<Discussion> findAll(Pageable pagination); List<Discussion> findAll();
List<Discussion> findAllById(Set<String> discussionIds); List<Discussion> findAllById(Set<String> discussionIds);

View File

@ -16,14 +16,11 @@ public interface MergeRequestRepository {
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states); Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
//TODO [28.01.2022]: Решить, нужно ли оставить
List<MergeRequest> findAllByAssignee(@NonNull Long userId);
MergeRequest save(MergeRequest mergeRequest); MergeRequest save(MergeRequest mergeRequest);
Optional<MergeRequest> findById(Long mergeRequestId); Optional<MergeRequest> findById(Long mergeRequestId);
Page<MergeRequest> findAll(Pageable pagination); List<MergeRequest> findAll();
List<MergeRequest> findAllById(Set<Long> mergeRequestIds); 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.ExistContainer;
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -37,7 +35,7 @@ public interface DiscussionService {
List<Discussion> createAll(@NonNull List<Discussion> newDiscussions); List<Discussion> createAll(@NonNull List<Discussion> newDiscussions);
Page<Discussion> getAll(@NonNull Pageable pagination); List<Discussion> getAll();
void deleteById(String discussionId); void deleteById(String discussionId);

View File

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

View File

@ -23,8 +23,6 @@ import okhttp3.FormBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -297,8 +295,8 @@ public class DiscussionServiceImpl implements DiscussionService {
} }
@Override @Override
public Page<Discussion> getAll(@NonNull Pageable pagination) { public List<Discussion> getAll() {
return repository.findAll(pagination); return repository.findAll();
} }
@Override @Override

View File

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

View File

@ -14,8 +14,6 @@ import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -45,8 +43,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
@RequiredArgsConstructor @RequiredArgsConstructor
public class DiscussionParser { public class DiscussionParser {
public static final int COUNT = 500;
private final DiscussionService discussionService; private final DiscussionService discussionService;
private final MergeRequestsService mergeRequestsService; private final MergeRequestsService mergeRequestsService;
private final ConversionService conversionService; private final ConversionService conversionService;
@ -59,18 +55,12 @@ public class DiscussionParser {
*/ */
public void scanNewDiscussion() { public void scanNewDiscussion() {
log.debug("Старт обработки новых дискуссий"); log.debug("Старт обработки новых дискуссий");
int page = 0; final List<MergeRequest> mergeRequests = mergeRequestsService.getAll();
Page<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT));
while (mergeRequestSheet.hasContent()) {
final List<MergeRequest> mergeRequests = mergeRequestSheet.getContent();
for (MergeRequest mergeRequest : mergeRequests) { for (MergeRequest mergeRequest : mergeRequests) {
processingMergeRequest(mergeRequest); processingMergeRequest(mergeRequest);
} }
mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT));
}
log.debug("Конец обработки новых дискуссий"); log.debug("Конец обработки новых дискуссий");
} }
@ -156,11 +146,7 @@ public class DiscussionParser {
*/ */
public void scanOldDiscussions() { public void scanOldDiscussions() {
log.debug("Старт обработки старых дискуссий"); log.debug("Старт обработки старых дискуссий");
int page = 0; final List<Discussion> discussions = discussionService.getAll();
Page<Discussion> discussionPage = discussionService.getAll(PageRequest.of(page, COUNT));
while (discussionPage.hasContent()) {
final List<Discussion> discussions = discussionPage.getContent();
// Удаляем обсуждения, которые потеряли свои MR // Удаляем обсуждения, которые потеряли свои MR
//TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия //TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия
@ -186,8 +172,6 @@ public class DiscussionParser {
discussionService.updateAll(newDiscussions); discussionService.updateAll(newDiscussions);
} }
discussionPage = discussionService.getAll(PageRequest.of(++page, COUNT));
}
log.debug("Конец обработки старых дискуссий"); log.debug("Конец обработки старых дискуссий");
} }

View File

@ -48,7 +48,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
@Service @Service
public class PipelineParser { public class PipelineParser {
public static final Integer COUNT = 100;
private static final Set<PipelineStatus> oldStatus = Set.of( private static final Set<PipelineStatus> oldStatus = Set.of(
CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL 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.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -45,8 +43,8 @@ public class DiscussionRepositoryImpl implements DiscussionRepository {
} }
@Override @Override
public Page<Discussion> findAll(Pageable pagination) { public List<Discussion> findAll() {
return jpaRepository.findAll(pagination); return jpaRepository.findAll();
} }
@Override @Override

View File

@ -28,11 +28,6 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
return jpaRepository.findAllIdByStateIn(statuses); return jpaRepository.findAllIdByStateIn(statuses);
} }
@Override
public List<MergeRequest> findAllByAssignee(@NonNull Long userId) {
return jpaRepository.findAllByAssigneeId(userId);
}
@Override @Override
public MergeRequest save(MergeRequest mergeRequest) { public MergeRequest save(MergeRequest mergeRequest) {
return jpaRepository.save(mergeRequest); return jpaRepository.save(mergeRequest);
@ -44,8 +39,8 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
} }
@Override @Override
public Page<MergeRequest> findAll(Pageable pagination) { public List<MergeRequest> findAll() {
return jpaRepository.findAll(pagination); return jpaRepository.findAll();
} }
@Override @Override