Merge pull request #3153 from spjspj/master

Increased performance function for finding a card in DB with a specif…
This commit is contained in:
spjspj 2017-04-18 20:59:45 +10:00 committed by GitHub
commit 0c6c81e58b
3 changed files with 20 additions and 6 deletions

View file

@ -49,7 +49,7 @@ public class CubeFromDeck extends DraftCube {
if (cards != null) {
for (DeckCardInfo card : cards.getCards()) {
cubeCards.add(new CardIdentity(card.getCardName(), ""));
cubeCards.add(new CardIdentity(card.getCardName(), card.getSetCode()));
}
}
}

View file

@ -420,6 +420,24 @@ public enum CardRepository {
return null;
}
public CardInfo findCardWPreferredSet(String name, String expansion, boolean caseInsensitive) {
List<CardInfo> cards;
if (caseInsensitive) {
cards = findCardsCaseInsensitive(name);
} else {
cards = findCards(name);
}
if (!cards.isEmpty()) {
CardInfo cardToUse = null;
for (CardInfo cardinfo : cards) {
if (cardinfo.getSetCode() != null && expansion != null && expansion.equalsIgnoreCase(cardinfo.getSetCode())) {
return cardinfo;
}
}
}
return findPreferedCoreExpansionCard(name, true);
}
public List<CardInfo> findCards(String name) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();

View file

@ -107,11 +107,7 @@ public abstract class DraftCube {
if (!cardId.getName().isEmpty()) {
CardInfo cardInfo = null;
if (!cardId.getExtension().isEmpty()) {
CardCriteria criteria = new CardCriteria().name(cardId.getName()).setCodes(cardId.extension);
List<CardInfo> cardList = CardRepository.instance.findCards(criteria);
if (cardList != null && !cardList.isEmpty()) {
cardInfo = cardList.get(0);
}
cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
} else {
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(cardId.getName(), false);
}