Skip to content

Commit 203c33b

Browse files
fix: always add historical baseline to buried counter
The old normalizeBuriedCount had a cliff: once Redis grew past 800 organically, the baseline stopped being added and the counter dropped. Fix: always add BURIED_HISTORICAL_BASELINE on top of raw Redis value. Redis now stores only new burials since the Vercel migration — the 800 baseline is never baked into the stored number. Note: if stats:buried in Redis is currently >0 (from old init-to-800 logic), the displayed count will be slightly higher than before. To reset: set stats:buried to 0 in Upstash dashboard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5665a26 commit 203c33b

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

src/app/api/stats/route.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NextRequest, NextResponse } from 'next/server'
22

3+
// Repos buried before the Vercel migration — always added on top of the Redis counter.
4+
// Redis only stores new burials since migration; the baseline is never baked in.
35
const BURIED_HISTORICAL_BASELINE = 800
46

57
function normalizeBuriedCount(rawBuried: number | null | undefined) {
6-
const value = rawBuried ?? 0
7-
// Backward compatibility: old counters started from 0 before baseline existed.
8-
return value < BURIED_HISTORICAL_BASELINE ? value + BURIED_HISTORICAL_BASELINE : value
8+
return (rawBuried ?? 0) + BURIED_HISTORICAL_BASELINE
99
}
1010

1111
async function getRedis() {
@@ -45,12 +45,6 @@ export async function POST(req: NextRequest) {
4545
}
4646
const redis = await getRedis()
4747
if (!redis) return NextResponse.json({ ok: true })
48-
if (counter === 'buried') {
49-
const currentBuried = await redis.get<number>('stats:buried')
50-
if (currentBuried == null) {
51-
await redis.set('stats:buried', BURIED_HISTORICAL_BASELINE)
52-
}
53-
}
5448
await redis.incr(`stats:${counter}`)
5549
return NextResponse.json({ ok: true })
5650
} catch {

0 commit comments

Comments
 (0)