[fix] Avoid unnecessary index creation costs

This commit is contained in:
lanceyq
2026-03-30 17:42:47 +08:00
parent d42db0ca33
commit 052c7c19b3
2 changed files with 9 additions and 5 deletions

View File

@@ -151,11 +151,6 @@ async def write(
# Step 3: Save all data to Neo4j database
step_start = time.time()
from app.repositories.neo4j.create_indexes import create_all_indexes
try:
await create_all_indexes()
except Exception as e:
logger.error(f"Error creating indexes: {e}", exc_info=True)
# 添加死锁重试机制
max_retries = 3

View File

@@ -62,6 +62,15 @@ async def lifespan(app: FastAPI):
logger.info("预定义模型加载已禁用 (LOAD_MODEL=false)")
logger.info("应用程序启动完成")
# 初始化 Neo4j 索引和约束(仅启动时执行一次)
try:
from app.repositories.neo4j.create_indexes import create_all_indexes
await create_all_indexes()
logger.info("Neo4j 索引和约束初始化完成")
except Exception as e:
logger.warning(f"Neo4j 索引初始化失败(服务仍可启动,但查询性能可能受影响): {e}")
yield
# 应用关闭事件
logger.info("应用程序正在关闭")