refactor(memory): extract workspace default config logic to service
- Extract default memory config retrieval logic from AppService to MemoryConfigService - Make get_workspace_default_config method public (remove underscore prefix) - Update AppService to delegate to MemoryConfigService for cleaner separation of concerns - Add legacy int config_id handling in delete_config method with appropriate warnings - Update delete_config signature to accept UUID or int types for backward compatibility - Improve code reusability and maintainability by centralizing memory config operations
This commit is contained in:
@@ -1316,43 +1316,18 @@ class AppService:
|
||||
Returns:
|
||||
Optional[uuid.UUID]: 默认记忆配置ID,如果不存在则返回 None
|
||||
"""
|
||||
from app.models.memory_config_model import MemoryConfig as MemoryConfigModel
|
||||
from app.services.memory_config_service import MemoryConfigService
|
||||
|
||||
# 查找工作空间的默认记忆配置
|
||||
stmt = (
|
||||
select(MemoryConfigModel.id)
|
||||
.where(
|
||||
MemoryConfigModel.workspace_id == workspace_id,
|
||||
MemoryConfigModel.is_default.is_(True),
|
||||
MemoryConfigModel.state.is_(True),
|
||||
)
|
||||
.limit(1)
|
||||
)
|
||||
service = MemoryConfigService(self.db)
|
||||
config = service.get_workspace_default_config(workspace_id)
|
||||
|
||||
config_id = self.db.scalars(stmt).first()
|
||||
|
||||
if config_id:
|
||||
return config_id
|
||||
|
||||
# 回退:获取最早创建的活跃配置
|
||||
stmt = (
|
||||
select(MemoryConfigModel.id)
|
||||
.where(
|
||||
MemoryConfigModel.workspace_id == workspace_id,
|
||||
MemoryConfigModel.state.is_(True),
|
||||
)
|
||||
.order_by(MemoryConfigModel.created_at.asc())
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
config_id = self.db.scalars(stmt).first()
|
||||
|
||||
if not config_id:
|
||||
if not config:
|
||||
logger.warning(
|
||||
f"工作空间没有可用的记忆配置: workspace_id={workspace_id}"
|
||||
)
|
||||
return None
|
||||
|
||||
return config_id
|
||||
return config.id
|
||||
|
||||
def _update_endusers_memory_config(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user