【问题标题】:Server-side paging possible?服务器端分页可能吗?
【发布时间】:2013-08-26 02:35:43
【问题描述】:

在 Java 应用程序中,我使用 Spring-Data 通过 REST 绑定访问 Neo4j 数据库。

用作上下文的 spring.xml 包含以下几行:

<neo4j:config graphDatabaseService="graphDatabaseService" />
<neo4j:repositories base-package="org.example.graph.repositories"/>

<bean id="graphDatabaseService"
    class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="http://example.org:1234/db/data" />
</bean>

我的仓库很简单:

public interface FooRepository extends GraphRepository<Foo> {   
}

现在,我想循环一下Foos:

for (Foo foo : fooRepository.findAll(new PageRequest(0, 5))) //...

但是,这个请求的性能很糟糕:它需要 400 多秒 (!) 才能完成。
经过一番调试,我发现 Spring-data 生成如下查询:

START `foo`=node:__types__(className="org.example.Foo") RETURN `foo`

然后看起来好像在客户端上完成了分页,并且所有Foos(超过 100,000 个)都转移到了客户端。使用 Web 界面向 Neo4j 服务器发出上述查询时,大约需要 60 秒。但是,如果我手动添加“LIMIT 5”,则执行时间会减少到 0.5 秒左右。

我做错了什么使 spring-data 不使用服务器端的 CYPHER 分页?
根据Programming Model

通过使用 REST API 转发这些调用,可以在服务器端高效地执行遍历和查询等昂贵的操作。

或者这是否排除了分页?
在这种情况下,我还有哪些其他选择?

【问题讨论】:

    标签: java performance rest neo4j spring-data-neo4j


    【解决方案1】:

    您可以执行以下操作来处理此服务器端。

    1. 在存储库中提供您自己的查询方法
    2. 密码查询应使用 order、skip 和 limit 并对其进行参数化,以便您可以按页传递 skip 和 limit 值。

    例如

    start john=node:users("name:pangea")
    match john-[:HAS_SEEN]-(movie)
    return movie
    order by movie.name? 
    skip 20
    limit 10
    

    【讨论】:

    • 好的,所以我必须手动执行此操作。不是我一直在寻找的答案,但现在我知道了。 :-)
    猜你喜欢
    • 2019-08-28
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多