feat(memory): add memory config caching to end_user model

- Add memory_config_id field to EndUser model for lazy caching of memory configuration
- Create get_end_user_memory_config_id() function for fast retrieval of cached config ID
- Implement lazy update mechanism in get_end_user_connected_config() to cache memory_config_id
- Optimize memory config lookup by storing config ID directly on end_user record
- Improve import organization and formatting in memory_agent_service.py
- Add indexed foreign key relationship to data_config table for efficient queries
This commit is contained in:
Ke Sun
2026-01-23 16:48:39 +08:00
parent cd4c93a5cb
commit d9fa9039bb
2 changed files with 43 additions and 3 deletions

View File

@@ -1,9 +1,11 @@
import datetime
import uuid
from sqlalchemy import Column, String, DateTime, ForeignKey, Text, BigInteger
from app.db import Base
from sqlalchemy import BigInteger, Column, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.db import Base
class EndUser(Base):
__tablename__ = "end_users"
@@ -18,6 +20,9 @@ class EndUser(Base):
created_at = Column(DateTime, default=datetime.datetime.now)
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
# Memory config association - updated lazily during conversation
memory_config_id = Column(Integer, ForeignKey("data_config.config_id"), nullable=True, index=True, comment="关联的记忆配置ID")
# 用户基本信息字段
position = Column(String, nullable=True, comment="职位")
department = Column(String, nullable=True, comment="部门")