Skip to content

Commit

Permalink
Adding index
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Dec 10, 2024
1 parent 26a887f commit 0ebe7a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ fun TranslationResult.persist() {
val nodes = this@persist.nodes
val edges = this@persist.allEdges<Edge<*>>()

neo4jSession.executeWrite { tx ->
tx.run("CREATE INDEX IF NOT EXISTS FOR (n:Node) ON (n.id)").consume()
}

log.info("Persisting {} nodes", nodes.size)
nodes.persist()

Expand Down Expand Up @@ -117,8 +121,8 @@ private fun Collection<Edge<*>>.persist() {
tx.run(
"""
UNWIND ${'$'}props AS map
MATCH (s {id: map.startId})
MATCH (e {id: map.endId})
MATCH (s:Node {id: map.startId})
MATCH (e:Node {id: map.endId})
CREATE (s)-[r:${it.key} {}]->(e)
"""
.trimIndent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package de.fraunhofer.aisec.cpg.v2

import de.fraunhofer.aisec.cpg.frontends.python.PythonLanguage
import de.fraunhofer.aisec.cpg.helpers.Benchmark
import de.fraunhofer.aisec.cpg.test.analyze
import de.fraunhofer.aisec.cpg_vis_neo4j.createTranslationResult
import java.nio.file.Path
Expand Down Expand Up @@ -60,7 +61,9 @@ class TestPersistence {
it.failOnError(false)
}

val bench = Benchmark(this.javaClass, "Persist")
neo4jSession.executeWrite { tx -> tx.run("MATCH (n) DETACH DELETE n").consume() }
result.persist()
bench.stop()
}
}

0 comments on commit 0ebe7a4

Please sign in to comment.