Skip to content

feat: 生成任务 SSE 推送替代前端轮询 #78

Closed

Description

@xiaocheny214

背景

当前角色图片生成和角色动作生成均采用 前端轮询 方案:

  1. 前端 POST 提交任务,后端返回 task_id
  2. 前端以 2s 间隔不断 GET /generation/tasks/{task_id} 直到 status 变为 completed / failed
  3. 前端读取 result 回填角色数据

问题:

  • 轮询产生大量无效请求,浪费带宽和服务器资源
  • 状态变更后仍需等待下一个轮询周期才能感知,体验不即时
  • 高并发下轮询请求压榨数据库连接池

目标: 改为 SSE(Server-Sent Events)推送,任务状态变更时服务端主动推送事件给前端。

Activity

  1. xiaocheny214 commented on Aug 5, 2026

    @xiaocheny214
    ContributorAuthor

    相关见8385016

  2. johnnyzhang-eng commented on Aug 12, 2026

    @johnnyzhang-eng
    Contributor

    服务端这半在 #182 里实现了(刚把 Refs 补上,之前漏了关联):GET /generation/tasks/{id}/stream 走 EventBus 按 (project_id, task_id) 双键隔离,终态直接推 completed/failed 并关流,订阅时若已是终态就立即推、不挂心跳。

    还没覆盖的两块:一是前端要真的停掉轮询并在终态 es.close()(服务端带 retry: 3000,不关的话浏览器每 3 秒重连重收同一条);二是主线全局 JWT 鉴权上线后 EventSource 不能带 header,这个端点不在白名单里会直接挂,得改 query token 或前端换 fetch-based SSE。

  3. added a commit that references this issue on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions