Files
backend_v2/db/migrations/2026-10-25-01-crawl-progress.sql
toom1996 51e3d13383 feat: 抓取进度可见 + 已入库秀预检(避免重复下载)
一、防重复下载
图片 key 是内容 sha1,不下载无法判断是否已存在;又没存 source_url,
于是每次重爬都把几百张已下过的图再下一遍(线上实测 Celine 62 分钟、0 新增)。
新增 GET /admin/internal/shows/covered?brand_uid=,按 (年份,季节,类型)
聚合已入库图片数,供 spider 抓前整场跳过。

二、进度可见
一次抓取可能跑几十分钟,此前只有 running/done,看不出「在干什么」,
也分不清「慢」和「卡死」。
- crawl_tasks 增加 progress_done/total/text/at
- POST /admin/internal/crawl/tasks/:id/progress(spider 每场 + 每批图片上报)
- GET /admin/crawl/live(页面 4 秒轮询,局部刷新状态/进度/已提交)
- progress_at 超过 10 分钟没更新标黄「可能卡住」
- 渲染测试守住进度列与轮询锚点
2026-10-25 21:22:56 +08:00

20 lines
1.3 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 抓取任务的执行进度。
--
-- 为什么需要:spider 一次抓取的品牌可能有几十场秀、每场几百张图,
-- 跑起来几分钟到几小时。此前只有 queued/running/done 三个状态,
-- 后台看到「执行中」就再无信息,既判断不了「在干什么」,
-- 也判断不了「是慢还是卡死」。
--
-- progress_at 与 updated_at 分开记:updated_at 会在领取/回报时变,
-- 而 progress_at 只有 spider 真的推进了才变——用它判卡死更准。
ALTER TABLE crawl_tasks
ADD COLUMN IF NOT EXISTS progress_done smallint NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS progress_total smallint NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS progress_text varchar(160) NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS progress_at bigint NOT NULL DEFAULT 0;
COMMENT ON COLUMN crawl_tasks.progress_done IS '已处理的秀数量(spider 上报)';
COMMENT ON COLUMN crawl_tasks.progress_total IS '本任务计划处理的秀数量(预检过滤后)';
COMMENT ON COLUMN crawl_tasks.progress_text IS '当前/最近一场秀的标题,供后台显示「正在抓什么」';
COMMENT ON COLUMN crawl_tasks.progress_at IS '最后一次进度心跳的 Unix 秒;用于判断任务是否卡死';