Skip to content

Performance: New FalkorDB connection created per API request #577

@gkorland

Description

@gkorland

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions