This commit is contained in:
@@ -745,7 +745,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
}
|
||||
|
||||
def build_full_graph_payload(
|
||||
max_nodes: int, *, highlight_id: Optional[str] = None
|
||||
max_nodes: Optional[int], *, highlight_id: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Attempt to render the entire reference graph by gathering every video that
|
||||
@@ -776,7 +776,8 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
nodes: Dict[str, Dict[str, Any]] = {}
|
||||
links: List[Dict[str, Any]] = []
|
||||
link_seen: Set[Tuple[str, str, str]] = set()
|
||||
batch_size = min(500, max(50, max_nodes * 2))
|
||||
node_limit = max_nodes if max_nodes and max_nodes > 0 else None
|
||||
batch_size = 500 if node_limit is None else min(500, max(50, node_limit * 2))
|
||||
truncated = False
|
||||
|
||||
def ensure_node(node_id: Optional[str], doc: Optional[Dict[str, Any]] = None) -> bool:
|
||||
@@ -799,7 +800,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
if not existing.get("date") and doc.get("date"):
|
||||
existing["date"] = doc.get("date")
|
||||
return True
|
||||
if len(nodes) >= max_nodes:
|
||||
if node_limit is not None and len(nodes) >= node_limit:
|
||||
return False
|
||||
channel_name = None
|
||||
channel_id = None
|
||||
@@ -836,7 +837,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
if not hits:
|
||||
break
|
||||
for hit in hits:
|
||||
if len(nodes) >= max_nodes:
|
||||
if node_limit is not None and len(nodes) >= node_limit:
|
||||
truncated = True
|
||||
stop_fetch = True
|
||||
break
|
||||
@@ -996,14 +997,17 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
depth = 1
|
||||
depth = max(0, min(depth, 3))
|
||||
|
||||
try:
|
||||
max_nodes = int(request.args.get("max_nodes", "200"))
|
||||
except ValueError:
|
||||
max_nodes = 200
|
||||
max_nodes = max(10, min(max_nodes, 800 if full_graph else 400))
|
||||
if full_graph:
|
||||
max_nodes = None
|
||||
else:
|
||||
try:
|
||||
max_nodes = int(request.args.get("max_nodes", "200"))
|
||||
except ValueError:
|
||||
max_nodes = 200
|
||||
max_nodes = max(10, min(max_nodes, 400))
|
||||
|
||||
if full_graph:
|
||||
payload = build_full_graph_payload(max_nodes, highlight_id=video_id or None)
|
||||
payload = build_full_graph_payload(None, highlight_id=video_id or None)
|
||||
else:
|
||||
payload = build_graph_payload(video_id, depth, max_nodes)
|
||||
if not payload["nodes"]:
|
||||
@@ -1011,7 +1015,9 @@ def create_app(config: AppConfig = CONFIG) -> Flask:
|
||||
jsonify({"error": f"Video '{video_id}' was not found in the index."}),
|
||||
404,
|
||||
)
|
||||
payload["meta"]["max_nodes"] = max_nodes
|
||||
payload["meta"]["max_nodes"] = (
|
||||
len(payload["nodes"]) if full_graph else max_nodes
|
||||
)
|
||||
return jsonify(payload)
|
||||
|
||||
@app.route("/api/years")
|
||||
|
||||
Reference in New Issue
Block a user