MCPcopy Create free account
hub / github.com/tirth8205/code-review-graph / get_flows

Function get_flows

code_review_graph/flows.py:571–610  ·  view source on GitHub ↗

Retrieve stored flows from the database. Args: store: The graph store. sort_by: Column to sort by (``criticality``, ``depth``, ``node_count``). limit: Maximum number of flows to return.

(
    store: GraphStore,
    sort_by: str = "criticality",
    limit: int = 50,
)

Source from the content-addressed store, hash-verified

569
570
571def get_flows(
572 store: GraphStore,
573 sort_by: str = "criticality",
574 limit: int = 50,
575) -> list[dict]:
576 """Retrieve stored flows from the database.
577
578 Args:
579 store: The graph store.
580 sort_by: Column to sort by (``criticality``, ``depth``, ``node_count``).
581 limit: Maximum number of flows to return.
582 """
583 allowed_sort = {"criticality", "depth", "node_count", "file_count", "name"}
584 if sort_by not in allowed_sort:
585 sort_by = "criticality"
586
587 order = "DESC" if sort_by in ("criticality", "depth", "node_count", "file_count") else "ASC"
588
589 # NOTE: get_flows reads from the flows table which is managed by
590 # the flows module; _conn access is documented coupling.
591 rows = store._conn.execute(
592 f"SELECT * FROM flows ORDER BY {sort_by} {order} LIMIT ?", # nosec B608
593 (limit,),
594 ).fetchall()
595
596 results: list[dict] = []
597 for row in rows:
598 results.append({
599 "id": row["id"],
600 "name": _sanitize_name(row["name"]),
601 "entry_point_id": row["entry_point_id"],
602 "depth": row["depth"],
603 "node_count": row["node_count"],
604 "file_count": row["file_count"],
605 "criticality": row["criticality"],
606 "path": json.loads(row["path_json"]),
607 "created_at": row["created_at"],
608 "updated_at": row["updated_at"],
609 })
610 return results
611
612
613def get_flow_by_id(store: GraphStore, flow_id: int) -> Optional[dict]:

Calls 1

_sanitize_nameFunction · 0.85