Merge pull request #7127 from Everlag/everlag/faster_deck_import_column

Deck import's performance improved (fixes #7126)
This commit is contained in:
Oleg Agafonov 2020-10-11 06:55:55 +02:00 committed by GitHub
commit cb3bb63cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -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();

View file

@ -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) {