From 71c94f85fb6b6326d4ac5d39164d86772fd0fd7b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 16 Feb 2024 16:15:13 -0300 Subject: [PATCH] Use cache when rerunning to allow pinned components --- src/backend/langflow/api/v1/chat.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 1cf14e85c..e586e192c 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -284,11 +284,16 @@ async def get_vertices( ): """Check the flow_id is in the flow_data_store.""" try: - 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) + # First, we need to check if the flow_id is in the cache + + if cache := chat_service.get_cache(flow_id): + graph = cache.get("result") + 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: vertices = graph.sort_up_to_vertex(component_id)