Оптимизация

This commit is contained in:
upagge 2020-03-02 20:39:54 +03:00
parent 1f9296b590
commit 4c603effc7
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
7 changed files with 42 additions and 17 deletions

View File

@ -13,7 +13,7 @@ public class AppConfig {
@Bean @Bean
public TaskScheduler taskScheduler() { public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(5); taskScheduler.setPoolSize(6);
return taskScheduler; return taskScheduler;
} }

View File

@ -4,6 +4,8 @@ import com.tsc.bitbucketbot.domain.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* TODO: Добавить описание класса. * TODO: Добавить описание класса.
* *
@ -16,4 +18,6 @@ public interface UserRepository extends JpaRepository<User, String> {
boolean existsByLogin(String login); boolean existsByLogin(String login);
List<User> findAllByTelegramIdNotNullAndTokenNotNull();
} }

View File

@ -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();
// }
//
//}

View File

@ -48,7 +48,7 @@ public class SchedulerPullRequest {
@Scheduled(fixedRate = 30000) @Scheduled(fixedRate = 30000)
public void checkClosePullRequest() { public void checkClosePullRequest() {
final List<User> users = userService.getAll(); final List<User> users = userService.getAllRegister();
for (User user : users) { for (User user : users) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class); Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
@ -98,7 +98,7 @@ public class SchedulerPullRequest {
@Scheduled(fixedRate = 30000) @Scheduled(fixedRate = 30000)
public void checkOldPullRequest() { public void checkOldPullRequest() {
final List<User> users = userService.getAll(); final List<User> users = userService.getAllRegister();
for (User user : users) { for (User user : users) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
@ -237,7 +237,7 @@ public class SchedulerPullRequest {
@Scheduled(fixedRate = 30000) @Scheduled(fixedRate = 30000)
public void checkNewPullRequest() { public void checkNewPullRequest() {
final List<User> users = userService.getAll(); final List<User> users = userService.getAllRegister();
for (User user : users) { for (User user : users) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {

View File

@ -18,12 +18,11 @@ public interface UserService {
Optional<User> getByLogin(String login); Optional<User> getByLogin(String login);
Optional<User> update(User user);
Set<String> existsByLogin(@NonNull Set<String> logins); Set<String> existsByLogin(@NonNull Set<String> logins);
Optional<User> reg(@NonNull User user); Optional<User> reg(@NonNull User user);
List<User> addAll(Set<User> newUsers); List<User> addAll(Set<User> newUsers);
List<User> getAllRegister();
} }

View File

@ -2,7 +2,6 @@ package com.tsc.bitbucketbot.service;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.stereotype.Service;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -17,12 +16,16 @@ import java.util.zip.GZIPInputStream;
* *
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Service
public class Utils { public class Utils {
private static Gson gson = new Gson(); 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; StringBuilder sb = null;
URL url; URL url;
URLConnection urlCon; URLConnection urlCon;

View File

@ -38,14 +38,6 @@ public class UserServiceImpl implements UserService {
return userRepository.findById(login); 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 @Override
public Set<String> existsByLogin(@NonNull Set<String> logins) { public Set<String> existsByLogin(@NonNull Set<String> logins) {
return logins.stream().filter(userRepository::existsById).collect(Collectors.toSet()); return logins.stream().filter(userRepository::existsById).collect(Collectors.toSet());
@ -70,4 +62,9 @@ public class UserServiceImpl implements UserService {
return userRepository.saveAll(newUsers); return userRepository.saveAll(newUsers);
} }
@Override
public List<User> getAllRegister() {
return userRepository.findAllByTelegramIdNotNullAndTokenNotNull();
}
} }