Skip to content

Commit a09520b

Browse files
fix: migrate buried counter to include baseline
Normalize old buried counter values so pre-baseline Redis data is interpreted as post-tracking increments and displayed with the 800 historical base. Made-with: Cursor
1 parent d79eacb commit a09520b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/app/api/stats/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { NextRequest, NextResponse } from 'next/server'
22

33
const BURIED_HISTORICAL_BASELINE = 800
44

5+
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
9+
}
10+
511
async function getRedis() {
612
if (!process.env.KV_REST_API_URL || !process.env.KV_REST_API_TOKEN) return null
713
try {
@@ -22,7 +28,7 @@ export async function GET() {
2228
redis.get<number>('stats:downloaded'),
2329
])
2430
return NextResponse.json({
25-
buried: buried ?? BURIED_HISTORICAL_BASELINE,
31+
buried: normalizeBuriedCount(buried),
2632
shared: shared ?? 0,
2733
downloaded: downloaded ?? 0,
2834
})

0 commit comments

Comments
 (0)