我正在使用带有mongodb的java ..我在下面的代码中遇到性能问题你可以优化这段代码吗?
我需要提高此功能的性能。
//第一个接收参数为associationId的函数。你能帮助我提高这个功能的性能..
public ArrayList<ResidentAssociationMapEntity> listUsersByAssociation(String
associationId) {
HashMap<String, Object> filterExpressions = new HashMap<String, Object>();
filterExpressions.put("associationId", associationId);
filterExpressions.put("residentStatus", 1);
List<ResidentAssociationMapEntity> residents =
DBManager.getInstance().getByMultipleFields(
ResidentAssociationMapEntity.class, filterExpressions);
if (residents != null && residents.size() > 0) {
for (ResidentAssociationMapEntity map : residents ) {
map.setUser(getUser(map.getUserId()));
}
}
return new ArrayList<ResidentAssociationMapEntity>(residents);
}
//获取用户功能
public UserEntity getUser(String userId) {
UserEntity entity = DBManager.getInstance().getById(UserEntity.class,
userId);
ResidentAssociationMapEntity map =
getResidentAssocaitionMap(entity.getUserId());
if (map != null) {
entity.setUnitNo(map.getUnitNumber() + "");
entity.setAssociationId(map.getAssociationId());
entity.setAssociationName(CompanyDAO.getInstance().getCompany(map.getAssocia
tionId()).getName());
}
return entity;
}
// getResidentAssocaitionMap function
private ResidentAssociationMapEntity getResidentAssocaitionMap(String
residentId) {
HashMap<String, Object> filterExpressions = new HashMap<String, Object>();
filterExpressions.put("userId", residentId);
filterExpressions.put("residentStatus", 1);
List<ResidentAssociationMapEntity> residents =
DBManager.getInstance().getByMultipleFields(
ResidentAssociationMapEntity.class, filterExpressions);
if (residents != null && residents.size() > 0) {
return residents.get(0);
}
return null;
}