Files
backend_v2/db/migrations/2026-10-25-02-brand-crawl-logs.sql
toom1996 64b264ee73 feat: 品牌抓取历史(brand_crawl_logs)+ 品牌页展示
crawl_tasks 每品牌只有一行(uq_crawl_tasks_brand),入队/完成都是覆盖,
答不了「什么时候爬过、爬了几次、哪次没抓到」。故新增 append-only 历史表:

- 在 Report 的同一事务里写一条:品牌 / 任务 / 状态 / 第几次尝试 /
  场次上限 / 实际上报场次 / 错误 / 执行者 / 领取与回报时间
- 写入后只保留该品牌最近 30 条(CrawlLogKeepPerBrand),
  历史用于排障而非归档,避免无限增长
- 品牌详情页新增「抓取历史」区块(结果 / 明细 / 耗时 / 执行者),
  与「更新记录」上下相邻,构成「抓取一次 → 每场入库结果」的完整链路

量级:每品牌每次抓取 1 行、约 200B(含索引);全站跑一遍 23237 行 ≈ 4.6MB。
2026-10-25 11:37:43 +08:00

27 lines
1.6 KiB
SQL
Raw 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.

-- 品牌抓取历史(append-only)。
--
-- 为什么另建一张表:crawl_tasks 每品牌只有一行(uq_crawl_tasks_brand),
-- 入队/完成都是覆盖,答不了「这个品牌什么时候爬过、爬了几次、哪次没抓到」。
-- 这里每次 worker 回报写一条,与 ingest_jobs(每场秀一条)拼成完整链路:
-- 抓取一次 → 上报 N 场 → 每场入库结果。
--
-- 量级:每品牌每次抓取 1 行,行宽约 160B(含索引约 200B)。
-- 全品牌跑一遍 23237 行 ≈ 4.6MB;按月重爬一年 ≈ 56MB。
-- 为防止无限增长,仓库层在写入后只保留每品牌最近 30 条(见 CrawlLogKeepPerBrand)。
CREATE TABLE IF NOT EXISTS brand_crawl_logs (
id bigserial PRIMARY KEY,
brand_id bigint NOT NULL,
task_id bigint NOT NULL DEFAULT 0,
status varchar(16) NOT NULL DEFAULT '', -- 回报的原始状态:done / failed
attempt smallint NOT NULL DEFAULT 1, -- 第几次尝试(含自动重试)
shows_requested smallint NOT NULL DEFAULT 0, -- 任务上的场次上限
shows_submitted integer NOT NULL DEFAULT 0, -- 实际上报了几场
message text NOT NULL DEFAULT '', -- spider 回报的错误/说明
worker varchar(64) NOT NULL DEFAULT '',
started_at bigint NOT NULL DEFAULT 0, -- 领取任务的时间
finished_at bigint NOT NULL DEFAULT 0 -- 回报时间
);
-- 品牌详情页:某品牌最近 N 条
CREATE INDEX IF NOT EXISTS idx_brand_crawl_logs_brand ON brand_crawl_logs (brand_id, id DESC);