对节点不必要的(?)附加标签请求

时间:2014-03-05 21:04:39

标签: rest neo4j label spring-data-neo4j

首先我的设置是:

spring-data-neo4j version: 3.0.0.RELEASE
spring-data-neo4j-rest version: 3.0.0.RELEASE 

我使用spring neo4j config和远程REST DB访问:

@Configuration
@EnableTransactionManagement 
@EnableNeo4jRepositories(basePackages = "my.package.repository")
public class Neo4JConfig extends Neo4jConfiguration {

@Bean
public GraphDatabaseService graphDatabaseService() {
    return new SpringRestGraphDatabase("http://localhost:7474/db/data");
}

}    

我将我的存储库设置为:

public interface ProductRepository extends GraphRepository<GraphProduct>{}

在该存储库上执行findAll()方法时:

Page<GraphProduct> products = productRepository.findAll(
            new PageRequest(page, size, sort != null ? new Sort(sort) : null));

日志显示(按预期)cypher查询以获取这些对象:

Executing remote cypher query: MATCH (`graphProduct`:`GraphProduct`) RETURN `graphProduct` params {}

问题

出乎意料的是,之后会为每个获取的节点发送后续请求:

Executing remote cypher query: match (n) where id(n)={nodeId} return labels(n) as labels params {nodeId=32}
Executing remote cypher query: match (n) where id(n)={nodeId} return labels(n) as labels params {nodeId=33}
...

你可以想象这会严重损害系统的性能(30个对象= 30个额外的REST请求)

我可以做一些有助于避免这些额外请求的事情吗? 这些数据是否可以一次性在所有节点的批量查询中返回?

更新

不幸的是,这个问题会持续一段时间。 我选择了@Gwendal google小组讨论链接https://groups.google.com/forum/#!topic/neo4j/GZ8XZ-TEc5c%5B1-25-false%5D,现在看来没有解决方法。

我能想到的唯一解决方案是返回节点属性

中的类名 来自GG讨论的

unfortunately labels are not returned from any of the endpoints with the nodes automatically, so they have to be fetched separately.

Sorry for that.

You can return to the Indexed type-representation strategy with using this config:

<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
    <constructor-arg index="0" ref="graphDatabase"/>
    <constructor-arg index="1" value="Indexed"/>
</bean>

<neo4j:config storeDirectory="graph.db" base-package="com.example.domain,com.example.domain2"/>
<neo4j:repositories base-package="com.example.repositories"/>

1 个答案:

答案 0 :(得分:0)

我在google网上发布了有关这些请求的消息:https://groups.google.com/forum/#!topic/neo4j/GZ8XZ-TEc5c%5B1-25-false%5D