Description
In api/graph.py, every function and class instantiation creates a fresh FalkorDB() connection:
def graph_exists(name: str):
db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379), ...)
def get_repos() -> list[str]:
db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379), ...)
class Graph:
def __init__(self, name):
self.db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379), ...)
This pattern is repeated for every API call, creating significant connection overhead.
Suggested Fix
Use a connection pool or module-level singleton:
from falkordb import FalkorDB
_db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379))
def graph_exists(name: str):
return name in _db.list_graphs()
Context
Found during code review of PR #522.
Description
In
api/graph.py, every function and class instantiation creates a freshFalkorDB()connection:This pattern is repeated for every API call, creating significant connection overhead.
Suggested Fix
Use a connection pool or module-level singleton:
Context
Found during code review of PR #522.