performance: fixed app freeze after first connection, moved sets and formats preload to client startup instead connection

This commit is contained in:
Oleg Agafonov 2023-11-30 21:55:08 +04:00
parent 0b0e947741
commit 1777a45ee4
2 changed files with 11 additions and 2 deletions

View file

@ -5,7 +5,6 @@ import mage.cards.action.ActionCallback;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.CardScanner; import mage.cards.repository.CardScanner;
import mage.cards.repository.ExpansionRepository;
import mage.cards.repository.RepositoryUtil; import mage.cards.repository.RepositoryUtil;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.chat.ChatPanelBasic; import mage.client.chat.ChatPanelBasic;
@ -33,6 +32,7 @@ import mage.client.util.*;
import mage.client.util.audio.MusicPlayer; import mage.client.util.audio.MusicPlayer;
import mage.client.util.gui.ArrowBuilder; import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.countryBox.CountryUtil; import mage.client.util.gui.countryBox.CountryUtil;
import mage.client.util.sets.ConstructedFormats;
import mage.client.util.stats.UpdateMemUsageTask; import mage.client.util.stats.UpdateMemUsageTask;
import mage.components.ImagePanel; import mage.components.ImagePanel;
import mage.components.ImagePanelStyle; import mage.components.ImagePanelStyle;
@ -269,6 +269,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
LOGGER.info("Images: search broken files..."); LOGGER.info("Images: search broken files...");
CardImageUtils.checkAndFixImageFiles(); CardImageUtils.checkAndFixImageFiles();
bootstrapSetsAndFormats();
if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) { if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) {
RateCard.bootstrapCardsAndRatings(); RateCard.bootstrapCardsAndRatings();
} }
@ -374,6 +376,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
} }
private void bootstrapSetsAndFormats() {
logger.info("Loading sets and formats...");
ConstructedFormats.ensureLists();
}
private void setWindowTitle() { private void setWindowTitle() {
setTitle(TITLE_NAME + " Client: " setTitle(TITLE_NAME + " Client: "
+ (VERSION == null ? "<not available>" : VERSION.toString()) + " Server: " + (VERSION == null ? "<not available>" : VERSION.toString()) + " Server: "

View file

@ -78,12 +78,14 @@ public final class ConstructedFormats {
} }
public static void ensureLists() { public static void ensureLists() {
if (underlyingSetCodesPerFormat.isEmpty()) { if (underlyingSetCodesPerFormat.isEmpty()
|| underlyingSetCodesPerFormat.values().stream().findFirst().get().isEmpty()) {
buildLists(); buildLists();
} }
} }
public static void buildLists() { public static void buildLists() {
underlyingSetCodesPerFormat.clear();
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>()); underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>()); underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>()); underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());