-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraversal.py
More file actions
30 lines (24 loc) · 987 Bytes
/
Copy pathtraversal.py
File metadata and controls
30 lines (24 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# backend/traversal.py
def get_reachable_nodes(entry_node_id, supabase_client):
"""
Performs a Breadth-First Search (BFS) to traverse the DAG
upward from the user's hierarchy level to find all 'parent' nodes.
"""
visited = set()
queue = [entry_node_id]
while queue:
current_id = queue.pop(0)
if current_id not in visited:
visited.add(current_id)
# Fetch parents of the current hierarchy level
# This looks at the hierarchy_levels table
response = supabase_client.table('hierarchy_levels')\
.select('parent_ids')\
.eq('id', current_id)\
.execute()
for row in response.data:
parents = row.get('parent_ids', [])
for parent_id in parents:
if parent_id not in visited:
queue.append(parent_id)
return list(visited)