mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
fix: 修复额外的内存泄露问题
1. hybrid_search.py: 修复 _search_vector 方法中的 SQLite 连接泄露 - 使用 with 语句包装数据库连接 - 添加异常处理确保连接正确关闭 2. symbol_extractor.py: 添加上下文管理器支持 - 实现 __enter__ 和 __exit__ 方法 - 支持 with 语句自动管理资源 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,15 @@ class SymbolExtractor:
|
||||
self.db_conn = sqlite3.connect(str(self.db_path))
|
||||
self._ensure_tables()
|
||||
|
||||
def __enter__(self) -> "SymbolExtractor":
|
||||
"""Context manager entry: connect to database."""
|
||||
self.connect()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
||||
"""Context manager exit: close database connection."""
|
||||
self.close()
|
||||
|
||||
def _ensure_tables(self) -> None:
|
||||
"""Create symbols and relationships tables if they don't exist."""
|
||||
if not self.db_conn:
|
||||
|
||||
@@ -241,12 +241,15 @@ class HybridSearchEngine:
|
||||
try:
|
||||
# Check if semantic chunks table exists
|
||||
import sqlite3
|
||||
conn = sqlite3.connect(index_path)
|
||||
cursor = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='semantic_chunks'"
|
||||
)
|
||||
has_semantic_table = cursor.fetchone() is not None
|
||||
conn.close()
|
||||
try:
|
||||
with sqlite3.connect(index_path) as conn:
|
||||
cursor = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='semantic_chunks'"
|
||||
)
|
||||
has_semantic_table = cursor.fetchone() is not None
|
||||
except sqlite3.Error as e:
|
||||
self.logger.error("Database check failed in vector search: %s", e)
|
||||
return []
|
||||
|
||||
if not has_semantic_table:
|
||||
self.logger.info(
|
||||
|
||||
Reference in New Issue
Block a user