Skip to content

feat: add cache prune-scores to drop outdated match results - #18

Merged
sangowu merged 1 commit into
mainfrom
feat/cache-prune-scores
Aug 7, 2026
Merged

sangowu merged 1 commit into
mainfrom
feat/cache-prune-scores

Conversation

@sangowu

@sangowu sangowu commented Aug 7, 2026

Copy link
Copy Markdown
Owner

清单最后一项。#15 / #16 / #17 把评分统一到了 job_matches(按 (job_id, cv_hash) 归属,带 prompt_version),但一直没有清理过时行的手段——bump matching.PROMPT_VERSION 之后,旧行会留在库里,除非 cache clear 整个清空。

用法

uv run jobradar cache prune-scores              # 删除 prompt 版本不是当前的行
uv run jobradar cache prune-scores --stale-cv   # 一并删除不属于最新 CV 的行
uv run jobradar cache prune-scores --orphans    # 一并删除职位已不存在的行
uv run jobradar cache prune-scores --yes        # 跳过确认

删除前先预览计数并要求确认。三个条件可能命中同一行,因此分类计数与去重后的 total 分开报告。

实现

cache.prune_job_matches(*, prompt_version, keep_cv_hash, drop_orphans, dry_run) 返回各分类计数 + total + deleted。条件独立启用;一个条件都不启用时是 no-op(不会误删全表)。CLI 先 dry_run=True 拿预览,确认后再实际执行。

验证

单测 6 个(TestPruneJobMatches):dry-run 不删除、只删过时版本、--stale-cv 可选、孤儿行仅在请求时删除、重叠行在 total 里只算一次、无条件时 no-op。全量 241 passed。

真实数据库端到端:

# 测试库(有 4 条 match_v9:zh)
before: [('match_v9:zh', 4)]
将删除 4 条匹配结果:
  prompt 版本不是 match_v11:zh:4 条
已删除 4 条匹配结果。
after : []

# 正式库
无参数    -> 没有需要清理的匹配结果(全部为 match_v11:zh)
--stale-cv -> 将删除 309 条(不属于当前 CV eaf1b010),回答 n 后正确取消

正式库的 309 条我没有删——那是历史 CV 的评分,是否保留由你决定。

🤖 Generated with Claude Code

https://claude.ai/code/session_012DbPx4FbswofbGn41anE1q

Removes job_matches rows that no longer reflect the current scoring setup so
the next search or `assess` recomputes them. Until now bumping
matching.PROMPT_VERSION left the old rows in place with no way to clear them
short of wiping the whole cache.

  prune-scores              drop rows whose prompt_version differs
  prune-scores --stale-cv   also drop rows belonging to any CV but the latest
  prune-scores --orphans    also drop rows whose job is gone from job_cache

Counts are previewed and confirmed before deletion (--yes skips the prompt).
The three conditions can match the same row, so each is reported separately
next to a de-duplicated total.

Verified on the test database, which held 4 match_v9:zh rows: the command
reported 4 and left the table empty. On the real cache the no-arg form
correctly reports nothing to clean (all rows are match_v11:zh) while
--stale-cv identifies 309 rows from previous CVs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012DbPx4FbswofbGn41anE1q
@sangowu
sangowu merged commit b47dfc0 into main Aug 7, 2026
2 checks passed
@sangowu
sangowu deleted the feat/cache-prune-scores branch August 7, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant