public List<Errand> interestFeed(Person person, int skip, int limit)
throws ControllerException {
person = validatePerson(person);
String query = String
.format("START n=node:ErrandLocation('withinDistance:[%.2f, %.2f, %.2f]') RETURN n ORDER BY n.added DESC SKIP %s LIMIT %S",
person.getLongitude(), person.getLatitude(),
person.getWidth(), skip, limit);
String queryFast = String
.format("START n=node:ErrandLocation('withinDistance:[%.2f, %.2f, %.2f]') RETURN n SKIP %s LIMIT %S",
person.getLongitude(), person.getLatitude(),
person.getWidth(), skip, limit);
Set<Errand> errands = new TreeSet<Errand>();
System.out.println(queryFast);
Result<Map<String, Object>> results = template.query(queryFast, null);
Iterator<Errand> objects = results.to(Errand.class).iterator();
return copyIterator (objects);
}
public List<Errand> copyIterator(Iterator<Errand> iter) {
Long start = System.currentTimeMillis();
Double startD = start.doubleValue();
List<Errand> copy = new ArrayList<Errand>();
while (iter.hasNext()) {
Errand e = iter.next();
copy.add(e);
System.out.println(e.getType());
}
Long end = System.currentTimeMillis();
Double endD = end.doubleValue();
p ((endD - startD)/1000);
return copy;
}
当我分析copyIterator函数时,只需6秒即可获取10个结果。我使用Spring Data Neo4j Rest连接在本地计算机上运行的Neo4j服务器。我甚至放了一个print函数来查看迭代器转换为列表的速度有多快,看起来确实很慢。每个iterator.next()都会进行一次新的Http调用吗?
答案 0 :(得分:1)
如果Errand是节点实体,那么是的,spring-data-neo4j将为每个实体进行http调用以获取其所有标签(neo4j的错误,当你在cypher中返回整个节点时,它不会返回标签)
您可以在org.springframework.data.neo4j.rest.SpringRestCypherQueryEngine
中启用调试级别日志记录,以记录转到neo4j的所有cypher语句。
要避免此次通话,请使用@QueryResult
http://docs.spring.io/spring-data/data-neo4j/docs/current/reference/html/#reference_programming-model_mapresult