Skip to content

Commit 0a7e8e0

Browse files
committed
fix: Changed direct and transitive package identification inside neo4j querys
1 parent 1561bc0 commit 0a7e8e0

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

app/schemas/operations/file_info_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def validate_max_depth(cls, value):
1919
@model_validator(mode='before')
2020
def set_max_depth_to_square(cls, values):
2121
if values.get('max_depth') != -1:
22-
values['max_depth'] = values.get('max_depth', 1) * 2
22+
values['max_depth'] = (values.get('max_depth', 1) * 2) - 1
2323
return values

app/services/repository_service.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def read_graph_for_req_file_info_operation(
114114
) YIELD path
115115
WITH
116116
last(nodes(path)) AS pkg,
117-
(length(path) - 1) / 2 AS depth,
117+
(length(path) + 1) / 2 AS depth,
118118
last(relationships(path)) AS rel
119119
WHERE '{node_type}' IN labels(pkg) AND type(rel) = 'REQUIRE'
120120
OPTIONAL MATCH (pkg:{node_type})-[:HAVE]->(v:Version)
@@ -130,14 +130,14 @@ async def read_graph_for_req_file_info_operation(
130130
}}) AS versions,
131131
rel.constraints AS constraints
132132
WITH {{
133-
package_name: pkg.name,
134-
package_vendor: pkg.vendor,
135-
package_constraints: constraints,
136-
versions: versions
133+
package_name: pkg.name,
134+
package_vendor: pkg.vendor,
135+
package_constraints: constraints,
136+
versions: versions
137137
}} AS enriched_pkg,
138138
depth
139139
WITH
140-
collect(CASE WHEN depth = 0 THEN enriched_pkg END) AS direct_deps,
140+
collect(CASE WHEN depth = 1 THEN enriched_pkg END) AS direct_deps,
141141
collect(CASE WHEN depth > 1 THEN {{node: enriched_pkg, depth: depth}} END) AS indirect_info
142142
WITH
143143
direct_deps,
@@ -196,7 +196,7 @@ async def read_graph_for_package_info_operation(
196196
) YIELD path
197197
WITH
198198
last(nodes(path)) AS pkg,
199-
(length(path) - 1) / 2 AS depth,
199+
length(path) / 2 AS depth,
200200
last(relationships(path)) AS rel
201201
WHERE '{node_type}' IN labels(pkg) AND type(rel) = 'REQUIRE'
202202
OPTIONAL MATCH (pkg:{node_type})-[:HAVE]->(v:Version)
@@ -212,14 +212,14 @@ async def read_graph_for_package_info_operation(
212212
}}) AS versions,
213213
rel.constraints AS constraints
214214
WITH {{
215-
package_name: pkg.name,
216-
package_vendor: pkg.vendor,
217-
package_constraints: constraints,
218-
versions: versions
215+
package_name: pkg.name,
216+
package_vendor: pkg.vendor,
217+
package_constraints: constraints,
218+
versions: versions
219219
}} AS enriched_pkg,
220220
depth
221221
WITH
222-
collect(CASE WHEN depth = 0 THEN enriched_pkg END) AS direct_deps,
222+
collect(CASE WHEN depth = 1 THEN enriched_pkg END) AS direct_deps,
223223
collect(CASE WHEN depth > 1 THEN {{node: enriched_pkg, depth: depth}} END) AS indirect_info
224224
WITH
225225
direct_deps,

0 commit comments

Comments
 (0)