From e1d3da507c1dc2f7d096b68f1ef0f3b6677d2dfb Mon Sep 17 00:00:00 2001
From: sivan <sivanduijn@gmail.com>
Date: Sat, 17 Apr 2021 09:19:29 +0200
Subject: [PATCH] use limit received in request

---
 internal/usecases/convertquery/aql.go        | 12 ++++++------
 internal/usecases/convertquery/aqlStructs.go |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/internal/usecases/convertquery/aql.go b/internal/usecases/convertquery/aql.go
index 02c7811..312a529 100644
--- a/internal/usecases/convertquery/aql.go
+++ b/internal/usecases/convertquery/aql.go
@@ -68,13 +68,13 @@ func createQuery(jsonQuery *parsedJSON) *string {
 			fromName := fmt.Sprintf("n%v", relation.EntityFrom)
 			ret += *createNodeLet(&jsonQuery.Entities[relation.EntityFrom], &fromName)
 
-			ret += *createRelationLetWithFromEntity(&relation, relationName, &jsonQuery.Entities)
+			ret += *createRelationLetWithFromEntity(&relation, relationName, &jsonQuery.Entities, jsonQuery.Limit)
 		} else if relation.EntityTo != -1 {
 			// if there is only a to-node
 			toName := fmt.Sprintf("n%v", relation.EntityTo)
 			ret += *createNodeLet(&jsonQuery.Entities[relation.EntityTo], &toName)
 
-			ret += *createRelationLetWithOnlyToEntity(&relation, relationName, &jsonQuery.Entities)
+			ret += *createRelationLetWithOnlyToEntity(&relation, relationName, &jsonQuery.Entities, jsonQuery.Limit)
 			// Add this relation to the list
 		} else {
 			fmt.Println("Relation-only queries are currently not supported")
@@ -151,7 +151,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta
 
 Return: a string containing a single LET-statement in AQL
 */
-func createRelationLetWithFromEntity(relation *relationStruct, name string, entities *[]entityStruct) *string {
+func createRelationLetWithFromEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string {
 	header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityFrom)
 	forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v OUTBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type)
 
@@ -172,7 +172,7 @@ func createRelationLetWithFromEntity(relation *relationStruct, name string, enti
 	}
 
 	relationFilterStmnt := *createConstraintStatements(&relation.Constraints, "p", true)
-	footer := "\tLIMIT 1000 \nRETURN DISTINCT p )\n"
+	footer := fmt.Sprintf("\tLIMIT %v \nRETURN DISTINCT p )\n", limit)
 
 	ret := header + forStatement + optionStmtn + vFilterStmnt + relationFilterStmnt + footer
 	return &ret
@@ -185,7 +185,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta
 
 Return: a string containing a single LET-statement in AQL
 */
-func createRelationLetWithOnlyToEntity(relation *relationStruct, name string, entities *[]entityStruct) *string {
+func createRelationLetWithOnlyToEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string {
 	header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityTo)
 	forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v INBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type)
 
@@ -194,7 +194,7 @@ func createRelationLetWithOnlyToEntity(relation *relationStruct, name string, en
 	optionStmtn := "\tOPTIONS { uniqueEdges: \"path\" }\n"
 
 	relationFilterStmnt := *createConstraintStatements(&relation.Constraints, "p", true)
-	footer := "\tLIMIT 1000 \nRETURN DISTINCT p )\n"
+	footer := fmt.Sprintf("\tLIMIT %v \nRETURN DISTINCT p )\n", limit)
 
 	ret := header + forStatement + optionStmtn + relationFilterStmnt + footer
 	return &ret
diff --git a/internal/usecases/convertquery/aqlStructs.go b/internal/usecases/convertquery/aqlStructs.go
index 208b889..c9a0424 100644
--- a/internal/usecases/convertquery/aqlStructs.go
+++ b/internal/usecases/convertquery/aqlStructs.go
@@ -14,6 +14,9 @@ type parsedJSON struct {
 	Return    returnStruct
 	Entities  []entityStruct
 	Relations []relationStruct
+
+	// Limit is for limiting the amount of paths AQL will return in a relation let statement
+	Limit int
 }
 
 // returnStruct holds the indices of the entities and relations that need to be returned
-- 
GitLab