Improvements to Merchant performance.
This commit is contained in:
@@ -290,17 +290,4 @@ public class DeckRequestHandler extends LotroServerRequestHandler implements Uri
|
||||
|
||||
return cardItems;
|
||||
}
|
||||
|
||||
private static class BasicCardItem implements CardItem {
|
||||
private String _blueprintId;
|
||||
|
||||
private BasicCardItem(String blueprintId) {
|
||||
_blueprintId = blueprintId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlueprintId() {
|
||||
return _blueprintId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,19 +115,16 @@ public class MerchantRequestHandler extends LotroServerRequestHandler implements
|
||||
CardCollection collection = _collectionsManager.getPlayerCollection(resourceOwner, "permanent");
|
||||
|
||||
Set<CardItem> cardItems = new HashSet<CardItem>();
|
||||
final Collection<CardCollection.Item> allItems = collection.getAll().values();
|
||||
for (CardCollection.Item item : allItems) {
|
||||
if (item.getCount() >= ownedMin)
|
||||
cardItems.add(item);
|
||||
}
|
||||
|
||||
if (ownedMin <= 0) {
|
||||
Set<CardItem> items = _merchantService.getSellableItems();
|
||||
for (CardItem item : items) {
|
||||
if (collection.getItemCount(item.getBlueprintId()) == 0)
|
||||
cardItems.addAll(_merchantService.getSellableItems());
|
||||
cardItems.addAll(collection.getAllCardsInCollection());
|
||||
} else {
|
||||
for (CardCollection.Item item : collection.getAll().values()) {
|
||||
if (item.getCount() >= ownedMin)
|
||||
cardItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
List<CardItem> filteredResult = _sortAndFilterCards.process(filter, cardItems, _library, _formatLibrary, _rarities);
|
||||
|
||||
List<CardItem> pageToDisplay = new ArrayList<CardItem>();
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
public class CachedMerchantDAO implements MerchantDAO, Cached {
|
||||
private MerchantDAO _delegate;
|
||||
private Map<String, Transaction> _blueprintIdLastTransaction = Collections.synchronizedMap(new LRUMap(4000));
|
||||
private Transaction _nullTransaction = new Transaction(null, 0, null, 0);
|
||||
|
||||
public CachedMerchantDAO(MerchantDAO delegate) {
|
||||
_delegate = delegate;
|
||||
@@ -33,10 +34,15 @@ public class CachedMerchantDAO implements MerchantDAO, Cached {
|
||||
|
||||
@Override
|
||||
public Transaction getLastTransaction(String blueprintId) {
|
||||
Transaction transaction = (Transaction) _blueprintIdLastTransaction.get(blueprintId);
|
||||
Transaction transaction = _blueprintIdLastTransaction.get(blueprintId);
|
||||
if (transaction == null) {
|
||||
transaction = _delegate.getLastTransaction(blueprintId);
|
||||
_blueprintIdLastTransaction.put(blueprintId, transaction);
|
||||
if (transaction == null)
|
||||
_blueprintIdLastTransaction.put(blueprintId, _nullTransaction);
|
||||
else
|
||||
_blueprintIdLastTransaction.put(blueprintId, transaction);
|
||||
} else if (transaction == _nullTransaction) {
|
||||
transaction = null;
|
||||
}
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
public class BasicCardItem implements CardItem {
|
||||
private String _blueprintId;
|
||||
|
||||
public BasicCardItem(String blueprintId) {
|
||||
_blueprintId = blueprintId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlueprintId() {
|
||||
return _blueprintId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
BasicCardItem that = (BasicCardItem) o;
|
||||
|
||||
if (_blueprintId != null ? !_blueprintId.equals(that._blueprintId) : that._blueprintId != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return _blueprintId != null ? _blueprintId.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface CardCollection extends OwnershipCheck {
|
||||
public int getCurrency();
|
||||
@@ -9,6 +10,8 @@ public interface CardCollection extends OwnershipCheck {
|
||||
|
||||
public int getItemCount(String blueprintId);
|
||||
|
||||
public Set<BasicCardItem> getAllCardsInCollection();
|
||||
|
||||
public static class Item implements CardItem {
|
||||
public enum Type {
|
||||
PACK, CARD, SELECTION
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.*;
|
||||
|
||||
public class DefaultCardCollection implements MutableCardCollection {
|
||||
private Map<String, Item> _counts = new LinkedHashMap<String, Item>();
|
||||
private Set<BasicCardItem> _basicItems = new HashSet<BasicCardItem>();
|
||||
private int _currency;
|
||||
|
||||
public DefaultCardCollection() {
|
||||
@@ -39,9 +40,10 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
public synchronized void addItem(String itemId, int toAdd) {
|
||||
if (toAdd > 0) {
|
||||
Item oldCount = _counts.get(itemId);
|
||||
if (oldCount == null)
|
||||
if (oldCount == null) {
|
||||
_counts.put(itemId, Item.createItem(itemId, toAdd));
|
||||
else
|
||||
_basicItems.add(new BasicCardItem(itemId));
|
||||
} else
|
||||
_counts.put(itemId, Item.createItem(itemId, toAdd + oldCount.getCount()));
|
||||
}
|
||||
}
|
||||
@@ -52,14 +54,20 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
Item oldCount = _counts.get(itemId);
|
||||
if (oldCount == null || oldCount.getCount() < toRemove)
|
||||
return false;
|
||||
if (oldCount.getCount() == toRemove)
|
||||
if (oldCount.getCount() == toRemove) {
|
||||
_counts.remove(itemId);
|
||||
else
|
||||
_basicItems.remove(new BasicCardItem(itemId));
|
||||
} else
|
||||
_counts.put(itemId, Item.createItem(itemId, oldCount.getCount() - toRemove));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<BasicCardItem> getAllCardsInCollection() {
|
||||
return Collections.unmodifiableSet(_basicItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized CardCollection openPack(String packId, String selection, PacksStorage packsStorage) {
|
||||
Item count = _counts.get(packId);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class SumCardCollection implements CardCollection {
|
||||
private List<CardCollection> _cardCollections;
|
||||
@@ -46,4 +44,12 @@ public class SumCardCollection implements CardCollection {
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<BasicCardItem> getAllCardsInCollection() {
|
||||
Set<BasicCardItem> result = new HashSet<BasicCardItem>();
|
||||
for (CardCollection cardCollection : _cardCollections)
|
||||
result.addAll(cardCollection.getAllCardsInCollection());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.gempukku.lotro.cards.packs.SetDefinition;
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.MerchantDAO;
|
||||
import com.gempukku.lotro.db.vo.CollectionType;
|
||||
import com.gempukku.lotro.game.BasicCardItem;
|
||||
import com.gempukku.lotro.game.CardItem;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.Player;
|
||||
@@ -23,7 +24,7 @@ public class MerchantService {
|
||||
private Map<String, PriceGuarantee> _priceGuarantees = Collections.synchronizedMap(new LRUMap(100));
|
||||
|
||||
private ReadWriteLock _lock = new ReentrantReadWriteLock(true);
|
||||
private Set<CardItem> _merchantableItems = new HashSet<CardItem>();
|
||||
private Set<BasicCardItem> _merchantableItems = new HashSet<BasicCardItem>();
|
||||
private Set<String> _merchantableStrings = new HashSet<String>();
|
||||
|
||||
private Map<String, Integer> _fixedPriceItems = new HashMap<String, Integer>();
|
||||
@@ -113,7 +114,7 @@ public class MerchantService {
|
||||
_merchantableStrings.add(blueprintId);
|
||||
}
|
||||
|
||||
public Set<CardItem> getSellableItems() {
|
||||
public Set<BasicCardItem> getSellableItems() {
|
||||
return Collections.unmodifiableSet(_merchantableItems);
|
||||
}
|
||||
|
||||
@@ -132,6 +133,7 @@ public class MerchantService {
|
||||
sellPrices.put(blueprintId, fixedPrice);
|
||||
} else {
|
||||
Integer buyPrice = _merchant.getCardBuyPrice(blueprintId, currentTime);
|
||||
|
||||
if (buyPrice != null)
|
||||
buyPrices.put(blueprintId, buyPrice);
|
||||
if (_merchantableStrings.contains(blueprintId)) {
|
||||
@@ -209,37 +211,6 @@ public class MerchantService {
|
||||
}
|
||||
}
|
||||
|
||||
private static class BasicCardItem implements CardItem {
|
||||
private String _blueprintId;
|
||||
|
||||
private BasicCardItem(String blueprintId) {
|
||||
_blueprintId = blueprintId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBlueprintId() {
|
||||
return _blueprintId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
BasicCardItem that = (BasicCardItem) o;
|
||||
|
||||
if (_blueprintId != null ? !_blueprintId.equals(that._blueprintId) : that._blueprintId != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return _blueprintId != null ? _blueprintId.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PriceGuarantee {
|
||||
private Map<String, Integer> _sellPrices;
|
||||
private Map<String, Integer> _buyPrices;
|
||||
|
||||
Reference in New Issue
Block a user