Skip to content

Commit c8fd931

Browse files
committed
Use LIMIT 1 instead of head(collect())
1 parent 81b5411 commit c8fd931

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

backend/infrahub/core/query/ipam.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG
180180
CALL (maybe_parent) {
181181
OPTIONAL MATCH (maybe_parent)-[r:IS_PART_OF]->(:Root)
182182
WHERE %(branch_filter)s
183-
WITH r
184183
ORDER BY r.branch_level DESC, r.from DESC, r.status ASC
185-
WITH head(collect(r)) AS latest_r
186-
RETURN latest_r IS NOT NULL AND latest_r.status = "active" AS node_is_active
184+
LIMIT 1
185+
RETURN r IS NOT NULL AND r.status = "active" AS node_is_active
187186
}
188187
WITH maybe_parent
189188
WHERE node_is_active = TRUE
@@ -193,11 +192,10 @@ async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG
193192
CALL (maybe_parent) {
194193
OPTIONAL MATCH (maybe_parent)-[r1:HAS_ATTRIBUTE]->(:Attribute {name: "prefix"})-[r2:HAS_VALUE]->(av:AttributeValue)
195194
WHERE all(r IN [r1, r2] WHERE (%(branch_filter)s))
196-
WITH av, r1, r2
197195
ORDER BY r1.branch_level DESC, r1.from DESC, r1.status ASC,
198196
r2.branch_level DESC, r2.from DESC, r2.status ASC
199-
WITH head(collect([av, r1, r2])) AS latest
200-
WITH latest[0] AS av, latest[1] AS r1, latest[2] AS r2
197+
LIMIT 1
198+
WITH av, r1, r2
201199
WHERE r1.status = "active" AND r2.status = "active"
202200
// ------------------
203201
// Re-check containment against the resolved branch-effective value

0 commit comments

Comments
 (0)