1212from api .analyzers .source_analyzer import SourceAnalyzer
1313from api .git_utils import git_utils
1414from api .git_utils .git_graph import AsyncGitGraph
15- from api .graph import Graph , AsyncGraphQuery , async_get_repos , async_graph_exists
15+ from api .graph import Graph , AsyncGraphQuery , async_get_repos
1616from api .info import async_get_repo_info
1717from api .llm import ask
1818from api .project import Project
19- from . auto_complete import async_prefix_search
19+
2020
2121# Load environment variables from .env file
2222load_dotenv ()
@@ -112,35 +112,34 @@ async def graph_entities(repo: str = Query(None), _=Depends(public_or_auth)):
112112 logging .error ("Missing 'repo' parameter in request." )
113113 return JSONResponse ({"status" : "Missing 'repo' parameter" }, status_code = 400 )
114114
115- if not await async_graph_exists (repo ):
116- logging .error ("Missing project %s" , repo )
117- return JSONResponse ({"status" : f"Missing project { repo } " }, status_code = 400 )
118-
115+ g = AsyncGraphQuery (repo )
119116 try :
120- g = AsyncGraphQuery ( repo )
121- try :
122- sub_graph = await g . get_sub_graph ( 500 )
123- finally :
124- await g .close ( )
117+ if not await g . graph_exists ():
118+ logging . error ( "Missing project %s" , repo )
119+ return JSONResponse ({ "status" : f"Missing project { repo } " }, status_code = 400 )
120+
121+ sub_graph = await g .get_sub_graph ( 500 )
125122
126123 logging .info ("Successfully retrieved sub-graph for repo: %s" , repo )
127124 return {"status" : "success" , "entities" : sub_graph }
128125
129126 except Exception as e :
130127 logging .exception ("Error retrieving sub-graph for repo '%s': %s" , repo , e )
131128 return JSONResponse ({"status" : "Internal server error" }, status_code = 500 )
129+ finally :
130+ await g .close ()
132131
133132
134133@app .post ('/api/get_neighbors' )
135134async def get_neighbors (data : NeighborsRequest , _ = Depends (public_or_auth )):
136135 """Get neighbors of a nodes list in the graph."""
137136
138- if not await async_graph_exists (data .repo ):
139- logging .error ("Missing project %s" , data .repo )
140- return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
141-
142137 g = AsyncGraphQuery (data .repo )
143138 try :
139+ if not await g .graph_exists ():
140+ logging .error ("Missing project %s" , data .repo )
141+ return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
142+
144143 neighbors = await g .get_neighbors (data .node_ids )
145144 finally :
146145 await g .close ()
@@ -154,10 +153,14 @@ async def get_neighbors(data: NeighborsRequest, _=Depends(public_or_auth)):
154153async def auto_complete (data : AutoCompleteRequest , _ = Depends (public_or_auth )):
155154 """Process auto-completion requests for a repository based on a prefix."""
156155
157- if not await async_graph_exists (data .repo ):
158- return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
156+ g = AsyncGraphQuery (data .repo )
157+ try :
158+ if not await g .graph_exists ():
159+ return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
159160
160- completions = await async_prefix_search (data .repo , data .prefix )
161+ completions = await g .prefix_search (data .prefix )
162+ finally :
163+ await g .close ()
161164 return {"status" : "success" , "completions" : completions }
162165
163166
@@ -191,12 +194,12 @@ async def repo_info(data: RepoRequest, _=Depends(public_or_auth)):
191194async def find_paths (data : FindPathsRequest , _ = Depends (public_or_auth )):
192195 """Find all paths between a source and destination node in the graph."""
193196
194- if not await async_graph_exists (data .repo ):
195- logging .error ("Missing project %s" , data .repo )
196- return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
197-
198197 g = AsyncGraphQuery (data .repo )
199198 try :
199+ if not await g .graph_exists ():
200+ logging .error ("Missing project %s" , data .repo )
201+ return JSONResponse ({"status" : f"Missing project { data .repo } " }, status_code = 400 )
202+
200203 paths = await g .find_paths (data .src , data .dest )
201204 finally :
202205 await g .close ()
@@ -291,7 +294,7 @@ async def list_commits(data: RepoRequest, _=Depends(public_or_auth)):
291294INDEX_HTML = STATIC_DIR / "index.html"
292295
293296@app .get ("/{full_path:path}" )
294- async def serve_spa (full_path : str ):
297+ def serve_spa (full_path : str ):
295298 """Serve React SPA — static assets or index.html catch-all."""
296299 file = (STATIC_DIR / full_path ).resolve ()
297300 if not file .is_relative_to (STATIC_DIR ):
0 commit comments