mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Fixes #7126 Introduce and use new lower_name column for card import
Profiling deck import revealed we spend most of the time running sql. The specific query compared against `lower(name)` which is not under an index. As a result, importing a deck could be quite slow since we were looking at every single card in the game. This change introduces a new indexed column, `lower_name`, and swaps findCardsCaseInsensitive to run against it. Optimally, we'd introduce an index here on `lower(name)` to avoid the unnecessary column. ie, `CREATE INDEX IF NOT EXISTS lower_name_index ON card (lower(name))` However, H2 does not currently support indices on expressions.
This commit is contained in:
parent
8c7d7f0b77
commit
45b84f1e8d
2 changed files with 8 additions and 2 deletions
|
@ -33,6 +33,12 @@ public class CardInfo {
|
|||
|
||||
@DatabaseField(indexName = "name_index")
|
||||
protected String name;
|
||||
/**
|
||||
* lower_name exists to speed up importing decks, specifically to provide an indexed column.
|
||||
* H2 does not support expressions in indices, so we need a physical column.
|
||||
*/
|
||||
@DatabaseField(indexName = "lower_name_index")
|
||||
protected String lower_name;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
protected String cardNumber;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
|
@ -107,6 +113,7 @@ public class CardInfo {
|
|||
|
||||
public CardInfo(Card card) {
|
||||
this.name = card.getName();
|
||||
this.lower_name = name.toLowerCase();
|
||||
this.cardNumber = card.getCardNumber();
|
||||
this.setCode = card.getExpansionSetCode();
|
||||
this.className = card.getClass().getCanonicalName();
|
||||
|
|
|
@ -58,7 +58,6 @@ public enum CardRepository {
|
|||
|
||||
TableUtils.createTableIfNotExists(connectionSource, CardInfo.class);
|
||||
cardDao = DaoManager.createDao(connectionSource, CardInfo.class);
|
||||
|
||||
eventSource.fireRepositoryDbLoaded();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CardRepository.class).error("Error creating card repository - ", ex);
|
||||
|
@ -490,7 +489,7 @@ public enum CardRepository {
|
|||
try {
|
||||
String sqlName = name.toLowerCase(Locale.ENGLISH).replaceAll("'", "''");
|
||||
GenericRawResults<CardInfo> rawResults = cardDao.queryRaw(
|
||||
"select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower(name) = '" + sqlName + '\'',
|
||||
"select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower_name = '" + sqlName + '\'',
|
||||
cardDao.getRawRowMapper());
|
||||
List<CardInfo> result = new ArrayList<>();
|
||||
for (CardInfo cardinfo : rawResults) {
|
||||
|
|
Loading…
Reference in a new issue