Mongo查询时间在多个环境中发行(Spring Boot)
我从事一个具有两个环境的项目,A& B,每个都有自己的数据库。我的Spring Boot(1.5.3)应用程序使用MongoDB,其中我正在根据枚举enumtype
type> type1 和type2
type2 。
现在,在Env。 A,当尝试获取enumType = type1
的所有条目时,我可以在数据库中看到的所有条目约为2000,这需要很长时间。获取条目,其中enumType = type2
需要正常的时间。
在Env。 b,当获取type1
条目时(约2m)时,这几乎不需要发生。获取type2
条目(450个条目)需要荒谬的时间。
在两种情况下,我都添加了一个type_1
索引(通过enumtype
上升),但是仍然存在这些奇怪的时间,以至于我尝试获取type2
Env B中的条目,我的应用程序崩溃。由于搜索逻辑在两个环境中都是相同的(在两种情况下都完全相同的应用程序运行),因此我不确定要解决此问题的其他操作。
代码很简单:
EntityController:
@GetMapping
public Page<Entity> getAll(@RequestParam EnumType type, OffsetPageRequest page) {
return entityService.getAll(type, page);
}
EntityService:
public Page<Entity> getAll(EnumType type, OffsetPageRequest page) {
return entityRepository.findByCriteria(type, page);
}
customizedentityRepository:
Page<Entity> findByCriteria(EnumType type, Pageable page);
userProfilerePositoryImpl:
@Override
public Page<Entity> findByCriteria(EnumType type, Pageable page) {
Query query = new Query().with(page);
List<Criteria> andCriteriaList = new ArrayList<>();
andCriteriaList.add(Criteria.where("type").is(type));
query.addCriteria(new Criteria().andOperator(andCriteriaList.toArray(new Criteria[0])));
return PageableExecutionUtils.getPage(mongoTemplate.find(query, Entity.class), page, () -> mongoTemplate.count(query, Entity.class));
}
enumtype:
public enum EnumType {
TYPE1,TYPE2;
private EnumType() {
}
}
两个应用程序都有相同的配置文件,唯一的区别是相应的数据库URL。
I work on a project with two environments, A & B, each with its own database. My spring boot (1.5.3) application uses mongodb, where I am querying a collection based on an enum EnumType
with values TYPE1
and TYPE2
.
Now, in env. A, when trying to fetch all entries where EnumType = TYPE1
, which I can see in my database are about 2000, this takes a long time. Fetching entries where EnumType = TYPE2
takes a normal amount of time.
In env. B, when fetching the TYPE1
entries, which are far more (approx 2M), this takes very little to happen. Fetching the TYPE2
entries (450 entries) takes a ridiculous amount of time.
I have added a type_1
index in both cases (get by EnumType
ascending), but these odd times remain, to the point where if I try to fetch the TYPE2
entries in env B, my application crashes. Since the search logic is the same in both environments (the exact same application runs in both cases), I'm not sure what else to do in order to fix this issue.
The code is simple:
EntityController:
@GetMapping
public Page<Entity> getAll(@RequestParam EnumType type, OffsetPageRequest page) {
return entityService.getAll(type, page);
}
EntityService:
public Page<Entity> getAll(EnumType type, OffsetPageRequest page) {
return entityRepository.findByCriteria(type, page);
}
CustomizedEntityRepository:
Page<Entity> findByCriteria(EnumType type, Pageable page);
UserProfileRepositoryImpl:
@Override
public Page<Entity> findByCriteria(EnumType type, Pageable page) {
Query query = new Query().with(page);
List<Criteria> andCriteriaList = new ArrayList<>();
andCriteriaList.add(Criteria.where("type").is(type));
query.addCriteria(new Criteria().andOperator(andCriteriaList.toArray(new Criteria[0])));
return PageableExecutionUtils.getPage(mongoTemplate.find(query, Entity.class), page, () -> mongoTemplate.count(query, Entity.class));
}
EnumType:
public enum EnumType {
TYPE1,TYPE2;
private EnumType() {
}
}
Both applications have the same configuration files, with the only differences being the corresponding database URLs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论