🐛 fix(chat.py): delete flow from cache if it already exists before initializing build

The code now checks if the flow already exists in the cache and deletes it before initializing the build. This ensures that the cache is always up to date and avoids any inconsistencies that may arise from having outdated data in the cache.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-23 09:28:25 -03:00
commit fc2e6c112e

View file

@ -39,6 +39,11 @@ async def init_build(graph_data: dict):
try:
flow_id = graph_data.get("id")
# Delete from cache if already exists
if flow_id in chat_manager.in_memory_cache:
with chat_manager.in_memory_cache._lock:
chat_manager.in_memory_cache.delete(flow_id)
logger.debug(f"Deleted flow {flow_id} from cache")
if flow_id is None:
raise ValueError("No ID provided")
flow_data_store[flow_id] = graph_data