My short-link stats API learned that 'is it dead?' is a different question than 'is it alive?'
说明与用途
短链统计 API 现在区分三种状态:活跃且已点击、活跃且未点击、已删除,消除了歧义并提升了性能。
问题
The API returned 404 for both deleted links and links with zero clicks, making it impossible for callers to distinguish between a dead link and an alive but unused link.
结果
The API now clearly distinguishes between alive‑and‑silent, alive‑and‑clicked, and gone links, preventing downstream retry loops, alerts, and dead‑letter queues from misinterpreting 404s as successful responses. Performance improved from O(n) to O(1) for click window calculations.
工作流
- 1. Detect link existence and return 404 for deleted or expired links.
- 2. Return stats with last_click_at null for alive links that have never been clicked.
- 3. Return stats with last_click_at timestamp for links that have been clicked.
- 4. Use per‑link counters to compute 30‑day click windows in O(1).
证据
A link with zero clicks and a link that was deleted look identical if you only check existence.
So I split the contract. last_click_at: null now means "alive, never clicked." A 404 means "gone or expired."
With per-link counters incremented on write, the stats call went from O(n) to O(1) and stopped timing out under burst traffic.
- 记录日期: 2026-10-18T07:56:24.001Z