Merge pull request #1258 from langchain-ai/nc/7aug/postgres-dont-sync-too-much

postgres: Avoid syncing pipeline unless actually needed
This commit is contained in:
Nuno Campos
2024-08-07 09:43:52 -07:00
committed by GitHub
2 changed files with 4 additions and 2 deletions
@@ -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
@@ -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