Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server-side paging possible?

In a Java application, I am using Spring-Data to access a Neo4j database via the REST binding.

The spring.xml used as a context contains the following lines:

<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>

My repository is very simple:

public interface FooRepository extends GraphRepository<Foo> {   
}

Now, I would like to loop through some Foos:

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

However, the performance of this request is awful: It takes over 400 seconds (!) to complete.
After a bit of debugging, I found out that Spring-data generates the following query:

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

It then looks like as if paging is done on the client and all Foos (more than 100,000) are transferred to the client. When issuing the above query to the Neo4j server using the web interface, it takes around 60 seconds. However, if I manually append a "LIMIT 5", the execution time reduces to around 0.5 seconds.

What am I doing wrong so that spring-data does not use server-side, CYPHER pagination?
According to Programming Model

the expensive operations like traversals and querying are executed efficiently on the server side by using the REST API to forward those calls.

Or does this exclude the pagination?
What other options do I have in this case?

like image 720
Matthias Avatar asked Sep 19 '26 20:09

Matthias


1 Answers

You can do the below to handle this server side.

  1. Provide your own query method in the repository
  2. The cypher query should use order, skip and limit and parameterize them so that you can pass in the skip and limit values on a per page basis.

E.g.

start john=node:users("name:pangea")
match john-[:HAS_SEEN]-(movie)
return movie
order by movie.name? 
skip 20
limit 10
like image 110
Aravind Yarram Avatar answered Sep 22 '26 10:09

Aravind Yarram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!