From 685148017ea5d0bc2758acf6a178bbd40279b6b6 Mon Sep 17 00:00:00 2001 From: Sheikah45 <66929319+Sheikah45@users.noreply.github.com> Date: Fri, 22 Dec 2023 22:06:31 -0500 Subject: [PATCH] Remove inappropriate usage of @Async (#3096) * Remove inappropriate usage of @Async * Remove unneeded method --- .../faforever/client/featuredmod/FeaturedModService.java | 3 --- .../java/com/faforever/client/game/GamePrefsService.java | 2 -- src/main/java/com/faforever/client/map/MapService.java | 2 -- src/main/java/com/faforever/client/mod/ModService.java | 3 --- .../com/faforever/client/update/CheckForUpdateTask.java | 8 +------- .../java/com/faforever/client/util/FileSizeReader.java | 3 +-- 6 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/faforever/client/featuredmod/FeaturedModService.java b/src/main/java/com/faforever/client/featuredmod/FeaturedModService.java index 4b48903606..08c2d8717e 100644 --- a/src/main/java/com/faforever/client/featuredmod/FeaturedModService.java +++ b/src/main/java/com/faforever/client/featuredmod/FeaturedModService.java @@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @@ -36,13 +35,11 @@ public class FeaturedModService { private final FeaturedModMapper featuredModMapper; private final GameUpdater gameUpdater; - @Async public CompletableFuture updateFeaturedMod(String featuredModName, Map featuredModFileVersions, Integer baseVersion, boolean forReplays) { return gameUpdater.update(featuredModName, featuredModFileVersions, baseVersion, forReplays); } - @Async public CompletableFuture updateFeaturedModToLatest(String featuredModName, boolean forReplays) { return updateFeaturedMod(featuredModName, null, null, forReplays); } diff --git a/src/main/java/com/faforever/client/game/GamePrefsService.java b/src/main/java/com/faforever/client/game/GamePrefsService.java index 00e0fe8c5d..9062616a73 100644 --- a/src/main/java/com/faforever/client/game/GamePrefsService.java +++ b/src/main/java/com/faforever/client/game/GamePrefsService.java @@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import java.io.IOException; @@ -88,7 +87,6 @@ public void writeActiveModUIDs(Set activeMods) throws IOException { Files.writeString(preferencesFile, preferencesContent); } - @Async public CompletableFuture patchGamePrefsForMultiInstances() { return CompletableFuture.runAsync(() -> { String prefsContent = readPreferencesFile(); diff --git a/src/main/java/com/faforever/client/map/MapService.java b/src/main/java/com/faforever/client/map/MapService.java index 081bfa0002..895f960ee1 100644 --- a/src/main/java/com/faforever/client/map/MapService.java +++ b/src/main/java/com/faforever/client/map/MapService.java @@ -66,7 +66,6 @@ import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -511,7 +510,6 @@ public CompletableFuture updateLatestVersionIfNecessary(MapVersi }); } - @Async public CompletableFuture getFileSize(MapVersionBean mapVersion) { return fileSizeReader.getFileSize(mapVersion.getDownloadUrl()); } diff --git a/src/main/java/com/faforever/client/mod/ModService.java b/src/main/java/com/faforever/client/mod/ModService.java index 09929d19b9..ddf9e2c7c2 100644 --- a/src/main/java/com/faforever/client/mod/ModService.java +++ b/src/main/java/com/faforever/client/mod/ModService.java @@ -50,7 +50,6 @@ import org.springframework.beans.factory.ObjectFactory; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; @@ -353,7 +352,6 @@ public Image loadThumbnail(ModVersionBean modVersion) { () -> themeService.getThemeImage(ThemeService.NO_IMAGE_AVAILABLE)); } - @Async public CompletableFuture getFileSize(ModVersionBean modVersion) { return fileSizeReader.getFileSize(modVersion.getDownloadUrl()); } @@ -394,7 +392,6 @@ public void destroy() { Optional.ofNullable(directoryWatcherThread).ifPresent(Thread::interrupt); } - @Async public CompletableFuture> updateAndActivateModVersions( final Collection selectedModVersions) { if (!preferences.isMapAndModAutoUpdate()) { diff --git a/src/main/java/com/faforever/client/update/CheckForUpdateTask.java b/src/main/java/com/faforever/client/update/CheckForUpdateTask.java index 3ce916326f..c851683d60 100644 --- a/src/main/java/com/faforever/client/update/CheckForUpdateTask.java +++ b/src/main/java/com/faforever/client/update/CheckForUpdateTask.java @@ -9,7 +9,6 @@ import com.faforever.client.task.CompletableTask; import com.faforever.client.update.ClientConfiguration.ReleaseInfo; import com.faforever.client.util.FileSizeReader; -import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; @@ -35,11 +34,6 @@ public CheckForUpdateTask(I18n i18n, PreferencesService preferencesService, File this.operatingSystem = operatingSystem; } - @VisibleForTesting - int getFileSize(URL url) { - return fileSizeReader.getFileSize(url).join(); - } - @Override protected UpdateInfo call() throws Exception { updateTitle(i18n.get("clientUpdateCheckTask.title")); @@ -59,7 +53,7 @@ protected UpdateInfo call() throws Exception { return null; } - int fileSize = getFileSize(downloadUrl); + int fileSize = fileSizeReader.getFileSize(downloadUrl).join(); return new UpdateInfo( version, diff --git a/src/main/java/com/faforever/client/util/FileSizeReader.java b/src/main/java/com/faforever/client/util/FileSizeReader.java index f947c4268e..242743a3df 100644 --- a/src/main/java/com/faforever/client/util/FileSizeReader.java +++ b/src/main/java/com/faforever/client/util/FileSizeReader.java @@ -2,7 +2,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpMethod; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.io.IOException; @@ -13,7 +12,7 @@ @Component @Slf4j public class FileSizeReader { - @Async + public CompletableFuture getFileSize(URL url) { return CompletableFuture.supplyAsync(() -> { HttpURLConnection connection = null;