Skip to content

Commit

Permalink
Remove controller caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 18, 2023
1 parent 0bbcce1 commit a797fb8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
40 changes: 2 additions & 38 deletions src/main/java/com/faforever/client/main/MainController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.faforever.client.main;

import ch.micheljung.fxwindow.FxStage;
import com.faforever.client.FafClientApplication;
import com.faforever.client.config.ClientProperties;
import com.faforever.client.exception.AssetLoadException;
import com.faforever.client.exception.FxmlLoadException;
import com.faforever.client.fx.AbstractViewController;
import com.faforever.client.fx.Controller;
import com.faforever.client.fx.FxApplicationThreadExecutor;
Expand Down Expand Up @@ -33,8 +31,6 @@
import com.faforever.client.user.LoginService;
import com.faforever.client.util.PopupUtil;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
Expand Down Expand Up @@ -68,11 +64,8 @@
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import static javafx.scene.layout.Background.EMPTY;

Expand All @@ -82,8 +75,6 @@
@RequiredArgsConstructor
public class MainController implements Controller<Node>, InitializingBean {

private final Cache<NavigationItem, AbstractViewController<?>> viewCache = CacheBuilder.newBuilder().build();

private final ClientProperties clientProperties;
private final I18n i18n;
private final NotificationService notificationService;
Expand All @@ -109,17 +100,10 @@ public class MainController implements Controller<Node>, InitializingBean {
protected Popup transientNotificationsPopup;
private NavigationItem currentItem;
private FxStage fxStage;
private boolean alwaysReloadTabs;

@Override
public void afterPropertiesSet() {
alwaysReloadTabs = Arrays.asList(environment.getActiveProfiles()).contains(FafClientApplication.PROFILE_RELOAD);

loginService.loggedInProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue && oldValue) {
viewCache.invalidateAll();
}

if (newValue) {
enterLoggedInState();
} else {
Expand Down Expand Up @@ -164,20 +148,8 @@ public void initialize() {

private void displayView(AbstractViewController<?> controller, NavigateEvent navigateEvent) {
Node node = controller.getRoot();
ObservableList<Node> children = contentPane.getChildren();

if (alwaysReloadTabs) {
children.clear();
}

if (!children.contains(node)) {
children.add(node);
JavaFxUtil.setAnchors(node, 0d);
}

if (!alwaysReloadTabs) {
Optional.ofNullable(currentItem).ifPresent(item -> getView(item).hide());
}
contentPane.getChildren().setAll(node);
JavaFxUtil.setAnchors(node, 0d);

Check warning on line 152 in src/main/java/com/faforever/client/main/MainController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/faforever/client/main/MainController.java#L151-L152

Added lines #L151 - L152 were not covered by tests
controller.display(navigateEvent);
}

Expand Down Expand Up @@ -363,15 +335,7 @@ public void onNavigateEvent(NavigateEvent navigateEvent) {
}

private AbstractViewController<?> getView(NavigationItem item) {
if (alwaysReloadTabs) {
return uiService.loadFxml(item.getFxmlFile());
}

try {
return viewCache.get(item, () -> uiService.loadFxml(item.getFxmlFile()));
} catch (ExecutionException e) {
throw new FxmlLoadException("Could not load tab view", e, "view.couldNotLoad", i18n.get(item.getI18nKey()));
}
}

private void displayImmediateNotification(ImmediateNotification notification) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/faforever/client/test/PlatformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.net.URL;
import java.util.Locale;

@Execution(ExecutionMode.CONCURRENT)
@Execution(ExecutionMode.SAME_THREAD)
@ExtendWith({MockitoExtension.class})
@MockitoSettings(strictness = Strictness.LENIENT)
//TODO figure out best way to refactor so that tests don't have to be lenient due to unnecessary stubbings spam
Expand Down

0 comments on commit a797fb8

Please sign in to comment.