Use cache when rerunning to allow pinned components

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-16 16:15:13 -03:00
commit 71c94f85fb

View file

@ -284,11 +284,16 @@ async def get_vertices(
): ):
"""Check the flow_id is in the flow_data_store.""" """Check the flow_id is in the flow_data_store."""
try: try:
flow: Flow = session.get(Flow, flow_id) # First, we need to check if the flow_id is in the cache
if not flow or not flow.data:
raise ValueError("Invalid flow ID") if cache := chat_service.get_cache(flow_id):
graph = Graph.from_payload(flow.data) graph = cache.get("result")
chat_service.set_cache(flow_id, graph) else:
flow: Flow = session.get(Flow, flow_id)
if not flow or not flow.data:
raise ValueError("Invalid flow ID")
graph = Graph.from_payload(flow.data)
chat_service.set_cache(flow_id, graph)
if component_id: if component_id:
vertices = graph.sort_up_to_vertex(component_id) vertices = graph.sort_up_to_vertex(component_id)