数据存储优化

back_recharge
mashiyu 2019-03-06 19:26:29 +08:00
parent 4e53e8e96c
commit db19eacd16
15 changed files with 13 additions and 17 deletions

View File

@ -9,7 +9,7 @@ public abstract class MongoBase {
private String rootId; private String rootId;
@Transient
private String mongoKey; //该级对应的mongodb的key private String mongoKey; //该级对应的mongodb的key
@Transient @Transient
private String rootCollection; private String rootCollection;

View File

@ -32,7 +32,6 @@ public class MapManager extends MongoBase {
public MapManager() { public MapManager() {
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.mapManager);
} }

View File

@ -20,7 +20,6 @@ public class MissionManager extends MongoBase {
public MissionManager(){ public MissionManager(){
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.missionManager);
} }

View File

@ -14,7 +14,6 @@ public class AdventureManager extends MongoBase {
public AdventureManager(){ public AdventureManager(){
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.adventureManager);
adventureStateInfoMap = new HashMap<>(); adventureStateInfoMap = new HashMap<>();
} }

View File

@ -14,7 +14,6 @@ public class EquipManager extends MongoBase {
public EquipManager() { public EquipManager() {
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.equipManager);
this.equipMap = new HashMap<>(); this.equipMap = new HashMap<>();
} }

View File

@ -5,6 +5,8 @@ import com.ljsd.jieling.config.SCHero;
import com.ljsd.jieling.config.SGameSetting; import com.ljsd.jieling.config.SGameSetting;
import com.ljsd.jieling.config.SHeroLevlConfig; import com.ljsd.jieling.config.SHeroLevlConfig;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.MongoKey;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic; import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.protocols.CommonProto; import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.util.KeyGenUtils; import com.ljsd.jieling.util.KeyGenUtils;
@ -39,10 +41,14 @@ public class Hero extends MongoBase {
private float curHp; private float curHp;
public Hero(){} public Hero(){
//绑定关系
this.setRootCollection(User._COLLECTION_NAME);
}
public Hero(String uid,int heroTid){ public Hero(String uid,int heroTid){
this.id = KeyGenUtils.produceIdByModule(UUIDEnum.HERO,uid); this.id = KeyGenUtils.produceIdByModule(UUIDEnum.HERO,uid);
SCHero scHero = SCHero.getsCHero().get(heroTid); SCHero scHero = SCHero.getsCHero().get(heroTid);
this.templateId = scHero.getId(); this.templateId = scHero.getId();
this.level = 1; this.level = 1;

View File

@ -14,7 +14,6 @@ public class HeroManager extends MongoBase {
public HeroManager() { public HeroManager() {
heroMap = new HashMap(); heroMap = new HashMap();
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.heroManager);
} }
public Map<String, Hero> getItemMap() { public Map<String, Hero> getItemMap() {
@ -27,7 +26,7 @@ public class HeroManager extends MongoBase {
public void addHero(Hero hero) throws Exception { public void addHero(Hero hero) throws Exception {
//绑定关系 //绑定关系
hero.init(hero.getId(),getMongoKey() + ".heroMap." + hero.getId()); hero.init(this.getRootId(),getMongoKey() + ".heroMap." + hero.getId());
updateString("heroMap." + hero.getId(), hero); updateString("heroMap." + hero.getId(), hero);
heroMap.put(hero.getId(), hero); heroMap.put(hero.getId(), hero);
} }

View File

@ -13,7 +13,6 @@ public class ItemManager extends MongoBase {
public ItemManager() { public ItemManager() {
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.itemManager);
} }
public Map<Integer, Item> getItemMap() { public Map<Integer, Item> getItemMap() {
@ -25,7 +24,7 @@ public class ItemManager extends MongoBase {
} }
public void addItem(Item item) throws Exception { public void addItem(Item item) throws Exception {
item.init(item.getRootId(), getMongoKey() + ".itemMap." + item.getItemId()); item.init(this.getRootId(), getMongoKey() + ".itemMap." + item.getItemId());
updateString("itemMap." + item.getItemId(), item); updateString("itemMap." + item.getItemId(), item);
itemMap.put(item.getItemId(), item); itemMap.put(item.getItemId(), item);
} }

View File

@ -13,7 +13,6 @@ public class MailManager extends MongoBase {
public MailManager(){ public MailManager(){
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.mailManager);
} }
public Map<String, Mail> getMailMap() { public Map<String, Mail> getMailMap() {

View File

@ -35,7 +35,6 @@ public class PlayerManager extends MongoBase {
public PlayerManager(){ public PlayerManager(){
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.playerManager);
} }
public String getOpenId() { public String getOpenId() {

View File

@ -12,7 +12,6 @@ public class PokemonManager extends MongoBase {
public PokemonManager() { public PokemonManager() {
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.pokemonManager);
this.pokemonMap = new HashMap<>(); this.pokemonMap = new HashMap<>();
} }

View File

@ -15,7 +15,7 @@ public class TeamPosManager extends MongoBase {
public TeamPosManager(){ public TeamPosManager(){
this.setRootCollection(User._COLLECTION_NAME); this.setRootCollection(User._COLLECTION_NAME);
this.setMongoKey(MongoKey.missionManager);
teamNames = new HashMap<>(3); teamNames = new HashMap<>(3);
teamPosForHero = new HashMap<>(3); teamPosForHero = new HashMap<>(3);
teamPosForPoken = new HashMap<>(3); teamPosForPoken = new HashMap<>(3);

View File

@ -96,7 +96,7 @@ public class UserManager {
public static User getUser(int uid) throws Exception { public static User getUser(int uid) throws Exception {
User user = userMap.get(uid); User user = userMap.get(Integer.toString(uid));
if (user != null) { if (user != null) {
return user; return user;
} }

View File

@ -23,7 +23,6 @@ public class WorkShopController extends MongoBase {
public WorkShopController(){ public WorkShopController(){
this.setRootCollection(MailingSystem._COLLECTION_NAME); this.setRootCollection(MailingSystem._COLLECTION_NAME);
this.setMongoKey(MongoKey.workShopController);
this.openBlueStateMap = new HashMap<>(); this.openBlueStateMap = new HashMap<>();