Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider defer save() database calls #208

Closed
ikwattro opened this issue Jul 25, 2016 · 2 comments
Closed

Consider defer save() database calls #208

ikwattro opened this issue Jul 25, 2016 · 2 comments

Comments

@ikwattro
Copy link

ikwattro commented Jul 25, 2016

If I would create let's say 100 Person entities in a for loop, I'll have to explicitly save them inside the loop.

for (int i = 0; i < 100; ++i) {
  Person p = new Person();
  p.save();

This would actually make 100 distinct requests to the database.

It would be more performant to defer the actions against the database until an explicit call. For example the code could look like the following (taken from the php-ogm ) :

for (int i = 0; i < 100; ++i {
   Person p = new Person();
   session.persist(p);
}
session.flush();

The call to session.persist(Object o) only inform the session (and thus the mapping context) that this entity should be managed.

When the call to session.flush(); is made, it will actually create the 100 nodes in batch.

NB: The OGM cypher query generator is already ready for this type of implementation

UNWIND {rows} as row CREATE (n:User) SET n += row.props

But you don't really benefit from it.

Nb: Very simple example showing the benefits being 10x faster

ikwattro@8a855f4

Referenced SO question with performance improvements test :

http://stackoverflow.com/questions/38556713/why-is-neo4js-insert-speed-so-low-in-this-example

@mangrish
Copy link
Contributor

mangrish commented Aug 2, 2016

This needs to also be added to the documentation somewhere.

@meistermeier
Copy link
Collaborator

Since collection can be persisted and result in a single query, this issue gets closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants