From 0ebe7a4f78ac57bf08f5d1f6a3a1f185b5cfbf64 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Tue, 10 Dec 2024 23:54:49 +0100 Subject: [PATCH] Adding index --- .../main/kotlin/de/fraunhofer/aisec/cpg/v2/Persistence.kt | 8 ++++++-- .../kotlin/de/fraunhofer/aisec/cpg/v2/TestPersistence.kt | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/v2/Persistence.kt b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/v2/Persistence.kt index c583a65c6c..376ea5ea96 100644 --- a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/v2/Persistence.kt +++ b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg/v2/Persistence.kt @@ -67,6 +67,10 @@ fun TranslationResult.persist() { val nodes = this@persist.nodes val edges = this@persist.allEdges>() + 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() @@ -117,8 +121,8 @@ private fun Collection>.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(), diff --git a/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg/v2/TestPersistence.kt b/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg/v2/TestPersistence.kt index b1f48c0aee..7685a0df95 100644 --- a/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg/v2/TestPersistence.kt +++ b/cpg-neo4j/src/test/kotlin/de/fraunhofer/aisec/cpg/v2/TestPersistence.kt @@ -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 @@ -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() } }