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

Fail to use map of nodes as custom query param #2791

Closed
rogelio-o opened this issue Sep 13, 2023 · 3 comments
Closed

Fail to use map of nodes as custom query param #2791

rogelio-o opened this issue Sep 13, 2023 · 3 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@rogelio-o
Copy link

We are saving a large list of nodes in Neo4j with many edges. Instead of defining the relationship as part of the node, we are saving all the nodes first and then all the edges with the Cypher query below. This reduces the number of calls to DB to 2 and improves the performance.

@Query("""
        UNWIND keys($relationships) as sourceId
        UNWIND $relationships[sourceId] as relationship
        MATCH
          (source:`package` {id: sourceId}),
          (target:`package` {id: relationship.__target__.__id__})
        MERGE (source)-[r:DEPENDS_ON]->(target)
        SET r += relationship.__properties__
      """)
  Mono<Void> mergeRelationships(@Param("relationships") Map<String, List<PackageRelationshipProperties>> relationships);

However, it does not work because entities are converted only when they are in a list, not in a map (and, of course, not in a map of lists). This happens here.

A perfect solution would be to reduce the number of queries to 2 in the saveAll method. However, if this is not possible, supporting the conversion of entities recursively will solve the problem.

@meistermeier
Copy link
Collaborator

There is now a 7.1.5-GH-2791-SNAPSHOT available in the Spring snapshot repo.
It adds the map(list(entity)) support as parameters.
Would be great to get feedback on this one.
Don't forget to add the snapshot (and milestone) repositories.

<repositories>
  <repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/milestone</url>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
  <repository>
    <id>spring-snapshots</id>
    <name>Spring Snapshots</name>
    <url>https://repo.spring.io/snapshot</url>
    <releases>
      <enabled>false</enabled>
    </releases>
  </repository>
</repositories>

@meistermeier meistermeier added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 15, 2023
@rogelio-o
Copy link
Author

It works perfectly. Thanks for the quick solution!

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 15, 2023
@meistermeier
Copy link
Collaborator

Thank you for the swift feedback 🙇
Will merge this next week for the coming 7.1.x version.

@meistermeier meistermeier added type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided labels Sep 15, 2023
@meistermeier meistermeier added this to the 7.1.5 (2023.0.5) milestone Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants