From 65be39779a7bc1f2c4e767fbfc0113c17135273c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A7=E6=B4=8B?= <714403855@qq.com> Date: Fri, 6 Mar 2026 10:41:43 +0800 Subject: [PATCH] feat:optimize search_by_fulltext --- src/memos/graph_dbs/polardb.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/memos/graph_dbs/polardb.py b/src/memos/graph_dbs/polardb.py index 6a0be0d32..8332efbc1 100644 --- a/src/memos/graph_dbs/polardb.py +++ b/src/memos/graph_dbs/polardb.py @@ -254,8 +254,13 @@ def _get_connection(self): if not self._semaphore.acquire(timeout=timeout): logger.warning(f"Timeout waiting for connection slot ({timeout}s)") raise RuntimeError( - f"Connection pool busy: could not acquire a slot within {timeout}s (all connections in use)." + f"Connection pool busy: acquire a slot within {timeout}s (all connections in use)." ) + logger.info( + "Connection pool usage: %s/%s", + self.connection_pool.maxconn - self._semaphore._value, + self.connection_pool.maxconn, + ) conn = None broken = False @@ -264,7 +269,7 @@ def _get_connection(self): logger.debug(f"Acquired connection {id(conn)} from pool") conn.autocommit = True with conn.cursor() as cur: - cur.execute("SELECT 1") + cur.execute(f'SET search_path = {self.db_name}_graph, ag_catalog, "$user", public;') yield conn except Exception as e: broken = True @@ -1777,6 +1782,7 @@ def search_by_fulltext( ) where_clause_cte = f"WHERE {' AND '.join(where_with_q)}" if where_with_q else "" query = f""" + /*+ Set(max_parallel_workers_per_gather 0) */ WITH q AS (SELECT to_tsquery('{tsquery_config}', %s) AS fq) SELECT {select_cols} FROM "{self.db_name}_graph"."Memory" m