Version: 0.9.35.dev.260422
后端: 1. 任务查询统一紧急性提升链路——LLM 工具与前端共享读时派生 + outbox 异步落库 - service/task.go:GetUserTasks 中读时提升逻辑抽取为独立方法 GetTasksWithUrgencyPromotion,返回 []model.Task 供两路复用 - service/agentsvc/agent.go:新增 GetTasksWithUrgencyPromotionFunc 函数注入字段 - service/agentsvc/agent_task_query.go:QueryTasksForTool 优先走统一提升链路,未注入时回退旧 taskRepo 直接读取 - service/agent_bridge.go:NewAgentServiceWithSchedule 接收 TaskService 并注入提升函数 - cmd/start.go:启动接线传入 taskSv 2. 移除未使用依赖 - go.mod:删除 github.com/bytedance/mockey
This commit is contained in:
@@ -13,31 +13,47 @@ import (
|
||||
)
|
||||
|
||||
func (s *AgentService) QueryTasksForTool(ctx context.Context, req newagentmodel.TaskQueryRequest) ([]newagentmodel.TaskQueryTaskRecord, error) {
|
||||
_ = ctx
|
||||
if req.UserID <= 0 {
|
||||
return nil, errors.New("invalid user_id in task query")
|
||||
}
|
||||
if s.taskRepo == nil {
|
||||
return nil, errors.New("task repository is nil")
|
||||
}
|
||||
|
||||
tasks, err := s.taskRepo.GetTasksByUserID(req.UserID)
|
||||
if err != nil {
|
||||
if errors.Is(err, respond.UserTasksEmpty) {
|
||||
return make([]newagentmodel.TaskQueryTaskRecord, 0), nil
|
||||
var tasks []model.Task
|
||||
var err error
|
||||
|
||||
// 优先使用统一提升链路(含缓存读取 + 读时派生 + outbox 异步落库)。
|
||||
if s.GetTasksWithUrgencyPromotionFunc != nil {
|
||||
tasks, err = s.GetTasksWithUrgencyPromotionFunc(ctx, req.UserID)
|
||||
if err != nil {
|
||||
if errors.Is(err, respond.UserTasksEmpty) {
|
||||
return make([]newagentmodel.TaskQueryTaskRecord, 0), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// 回退:未注入时走旧的 taskRepo 直接读取(无缓存、无持久化)。
|
||||
if s.taskRepo == nil {
|
||||
return nil, errors.New("task repository is nil")
|
||||
}
|
||||
tasks, err = s.taskRepo.GetTasksByUserID(req.UserID)
|
||||
if err != nil {
|
||||
if errors.Is(err, respond.UserTasksEmpty) {
|
||||
return make([]newagentmodel.TaskQueryTaskRecord, 0), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
now := time.Now()
|
||||
for i := range tasks {
|
||||
applyReadTimeUrgencyPromotion(&tasks[i], now)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
// 过滤、排序、截断。
|
||||
filtered := make([]model.Task, 0, len(tasks))
|
||||
for _, originalTask := range tasks {
|
||||
currentTask := originalTask
|
||||
applyReadTimeUrgencyPromotion(¤tTask, now)
|
||||
if !taskMatchesQueryFilter(currentTask, req) {
|
||||
for _, task := range tasks {
|
||||
if !taskMatchesQueryFilter(task, req) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, currentTask)
|
||||
filtered = append(filtered, task)
|
||||
}
|
||||
|
||||
sortTasksForQuery(filtered, req)
|
||||
|
||||
Reference in New Issue
Block a user