Оптимизация
This commit is contained in:
parent
1f9296b590
commit
4c603effc7
@ -13,7 +13,7 @@ public class AppConfig {
|
||||
@Bean
|
||||
public TaskScheduler taskScheduler() {
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
taskScheduler.setPoolSize(5);
|
||||
taskScheduler.setPoolSize(6);
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import com.tsc.bitbucketbot.domain.entity.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
*
|
||||
@ -16,4 +18,6 @@ public interface UserRepository extends JpaRepository<User, String> {
|
||||
|
||||
boolean existsByLogin(String login);
|
||||
|
||||
List<User> findAllByTelegramIdNotNullAndTokenNotNull();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
//package com.tsc.bitbucketbot.scheduler;
|
||||
//
|
||||
//import com.tsc.bitbucketbot.domain.entity.User;
|
||||
//import com.tsc.bitbucketbot.service.UserService;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.scheduling.annotation.Scheduled;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Service
|
||||
//@RequiredArgsConstructor
|
||||
//public class SchedulerNotification {
|
||||
//
|
||||
// private final UserService userService;
|
||||
//
|
||||
// @Scheduled(cron = "0 9 * * MON-FRI")
|
||||
// public void goodMorning() {
|
||||
// List<User> users = userService.getAllRegister();
|
||||
// }
|
||||
//
|
||||
//}
|
@ -48,7 +48,7 @@ public class SchedulerPullRequest {
|
||||
|
||||
@Scheduled(fixedRate = 30000)
|
||||
public void checkClosePullRequest() {
|
||||
final List<User> users = userService.getAll();
|
||||
final List<User> users = userService.getAllRegister();
|
||||
for (User user : users) {
|
||||
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class);
|
||||
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
|
||||
@ -98,7 +98,7 @@ public class SchedulerPullRequest {
|
||||
|
||||
@Scheduled(fixedRate = 30000)
|
||||
public void checkOldPullRequest() {
|
||||
final List<User> users = userService.getAll();
|
||||
final List<User> users = userService.getAllRegister();
|
||||
for (User user : users) {
|
||||
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
|
||||
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
|
||||
@ -237,7 +237,7 @@ public class SchedulerPullRequest {
|
||||
|
||||
@Scheduled(fixedRate = 30000)
|
||||
public void checkNewPullRequest() {
|
||||
final List<User> users = userService.getAll();
|
||||
final List<User> users = userService.getAllRegister();
|
||||
for (User user : users) {
|
||||
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
|
||||
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
|
||||
|
@ -18,12 +18,11 @@ public interface UserService {
|
||||
|
||||
Optional<User> getByLogin(String login);
|
||||
|
||||
Optional<User> update(User user);
|
||||
|
||||
Set<String> existsByLogin(@NonNull Set<String> logins);
|
||||
|
||||
Optional<User> reg(@NonNull User user);
|
||||
|
||||
List<User> addAll(Set<User> newUsers);
|
||||
|
||||
List<User> getAllRegister();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.tsc.bitbucketbot.service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -17,12 +16,16 @@ import java.util.zip.GZIPInputStream;
|
||||
*
|
||||
* @author upagge [30.01.2020]
|
||||
*/
|
||||
@Service
|
||||
public class Utils {
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
public static <T> Optional<T> urlToJson(@NonNull String urlValue, String token, Class<T> classOfT) {
|
||||
private Utils() {
|
||||
throw new IllegalStateException("Утилитарный класс");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> Optional<T> urlToJson(String urlValue, String token, Class<T> classOfT) {
|
||||
StringBuilder sb = null;
|
||||
URL url;
|
||||
URLConnection urlCon;
|
||||
|
@ -38,14 +38,6 @@ public class UserServiceImpl implements UserService {
|
||||
return userRepository.findById(login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> update(User user) {
|
||||
if (userRepository.existsById(user.getLogin())) {
|
||||
return Optional.of(userRepository.save(user));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> existsByLogin(@NonNull Set<String> logins) {
|
||||
return logins.stream().filter(userRepository::existsById).collect(Collectors.toSet());
|
||||
@ -70,4 +62,9 @@ public class UserServiceImpl implements UserService {
|
||||
return userRepository.saveAll(newUsers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getAllRegister() {
|
||||
return userRepository.findAllByTelegramIdNotNullAndTokenNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user