mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 02:52:02 -08:00
* Improved connection performance on new release, no more empty cards on startup;
This commit is contained in:
parent
6846db75f4
commit
f788af1f6a
4 changed files with 20 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ package mage.client;
|
||||||
import mage.cards.action.ActionCallback;
|
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.ExpansionRepository;
|
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;
|
||||||
|
|
@ -215,7 +216,15 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
LOGGER.fatal(null, ex);
|
LOGGER.fatal(null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DATA PREPARE
|
||||||
RepositoryUtil.bootstrapLocalDb();
|
RepositoryUtil.bootstrapLocalDb();
|
||||||
|
// re-create database on empty (e.g. after new build cleaned db on startup)
|
||||||
|
if (RepositoryUtil.CARD_DB_RECREATE_BY_CLIENT_SIDE && RepositoryUtil.isDatabaseEmpty()) {
|
||||||
|
LOGGER.info("DB: creating cards database");
|
||||||
|
CardScanner.scan();
|
||||||
|
LOGGER.info("Done.");
|
||||||
|
}
|
||||||
|
|
||||||
if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) {
|
if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) {
|
||||||
RateCard.bootstrapCardsAndRatings();
|
RateCard.bootstrapCardsAndRatings();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
/*
|
|
||||||
* ConnectDialog.java
|
|
||||||
*
|
|
||||||
* Created on 20-Jan-2010, 9:37:07 PM
|
|
||||||
*/
|
|
||||||
package mage.client.dialog;
|
package mage.client.dialog;
|
||||||
|
|
||||||
import mage.cards.repository.CardRepository;
|
import mage.cards.repository.RepositoryUtil;
|
||||||
import mage.cards.repository.ExpansionRepository;
|
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.choices.ChoiceImpl;
|
import mage.choices.ChoiceImpl;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
|
|
@ -509,9 +503,7 @@ public class ConnectDialog extends MageDialog {
|
||||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||||
connection.setUsername(this.txtUserName.getText().trim());
|
connection.setUsername(this.txtUserName.getText().trim());
|
||||||
connection.setPassword(String.valueOf(this.txtPassword.getPassword()).trim());
|
connection.setPassword(String.valueOf(this.txtPassword.getPassword()).trim());
|
||||||
// force to redownload db
|
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected() || RepositoryUtil.isDatabaseEmpty());
|
||||||
boolean redownloadDatabase = (ExpansionRepository.instance.getSetByCode("GRN") == null || CardRepository.instance.findCard("Island") == null);
|
|
||||||
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected() || redownloadDatabase);
|
|
||||||
String allMAC = "";
|
String allMAC = "";
|
||||||
try {
|
try {
|
||||||
allMAC = Connection.getMAC();
|
allMAC = Connection.getMAC();
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,9 @@ public class SessionImpl implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDatabase(boolean forceDBComparison, ServerState serverState) {
|
private void updateDatabase(boolean forceDBComparison, ServerState serverState) {
|
||||||
|
// download NEW cards/sets, but do not download data fixes (it's an old and rare feature from old clients, e.g. one client for different servers with different cards)
|
||||||
|
// use case: server gets new minor version with new cards, old client can get that cards too without donwload new version
|
||||||
|
|
||||||
// sets
|
// sets
|
||||||
long expansionDBVersion = ExpansionRepository.instance.getContentVersionFromDB();
|
long expansionDBVersion = ExpansionRepository.instance.getContentVersionFromDB();
|
||||||
if (forceDBComparison || serverState.getExpansionsContentVersion() > expansionDBVersion) {
|
if (forceDBComparison || serverState.getExpansionsContentVersion() > expansionDBVersion) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
public final class RepositoryUtil {
|
public final class RepositoryUtil {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(RepositoryUtil.class);
|
private static final Logger logger = Logger.getLogger(RepositoryUtil.class);
|
||||||
|
public static final boolean CARD_DB_RECREATE_BY_CLIENT_SIDE = true; // re-creates db from client (best performance) or downloads from server on connects (can be slow)
|
||||||
|
|
||||||
public static void bootstrapLocalDb() {
|
public static void bootstrapLocalDb() {
|
||||||
// call local db to init all sets and cards repository (need for correct updates cycle, not on random request)
|
// call local db to init all sets and cards repository (need for correct updates cycle, not on random request)
|
||||||
|
|
@ -103,4 +104,9 @@ public final class RepositoryUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDatabaseEmpty() {
|
||||||
|
return ExpansionRepository.instance.getSetByCode("GRN") == null
|
||||||
|
|| CardRepository.instance.findCard("Island") == null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue