From 2bd9eb429839025d1ee62bbc632c0e588ee3b661 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Wed, 7 Aug 2024 09:40:18 -0700 Subject: [PATCH] postgres: Avoid syncing pipeline unless actually needed --- .../langgraph/checkpoint/postgres/__init__.py | 3 ++- libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py index b2c187ab5..3c12c4d24 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py @@ -239,7 +239,8 @@ class PostgresSaver(BasePostgresSaver): with self.conn.cursor(binary=True) as cur: yield cur finally: - self.pipe.sync() + if pipeline: + self.pipe.sync() elif pipeline: # a connection not in pipeline mode can only be used by one # thread/coroutine at a time, so we acquire a lock diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py index e9750d4a1..dd150535c 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py @@ -247,7 +247,8 @@ class AsyncPostgresSaver(BasePostgresSaver): async with self.conn.cursor(binary=True) as cur: yield cur finally: - await self.pipe.sync() + if pipeline: + await self.pipe.sync() elif pipeline: # a connection not in pipeline mode can only be used by one # thread/coroutine at a time, so we acquire a lock