fix(wiki): make footer counter all-time cumulative, not a 30-day window
Sum the full visits history instead of windowing to 30 days, so the agent/human counts grow monotonically since launch (data is never GC'd).
This commit is contained in:
1 parent
ee28390a2c
commit
c2257fe6f3
1 file changed
+5
-12
@@ -1,7 +1,7 @@
|
|||||||
// GET /api/stats — aggregate numbers for the wiki footer.
|
// GET /api/stats — aggregate numbers for the wiki footer.
|
||||||
//
|
//
|
||||||
// web : agent-vs-human page views to vibetrading.wiki (last 30 days),
|
// web : all-time agent-vs-human page views to vibetrading.wiki, counted
|
||||||
// counted server-side by _middleware.js into D1. Authoritative.
|
// server-side by _middleware.js into D1 (cumulative since launch).
|
||||||
// pypi : install counts for `vibe-trading-ai` (pypistats public API), with a
|
// pypi : install counts for `vibe-trading-ai` (pypistats public API), with a
|
||||||
// last-good D1 cache so an occasional flaky/rate-limited upstream call
|
// last-good D1 cache so an occasional flaky/rate-limited upstream call
|
||||||
// never blanks the footer.
|
// never blanks the footer.
|
||||||
@@ -10,8 +10,6 @@
|
|||||||
// client-side (main.js `initStars`), so adding them would only duplicate work
|
// client-side (main.js `initStars`), so adding them would only duplicate work
|
||||||
// and introduce a rate-limited call. Never throws to the client.
|
// and introduce a rate-limited call. Never throws to the client.
|
||||||
|
|
||||||
const WINDOW_DAYS = 30;
|
|
||||||
|
|
||||||
async function getPypi(env) {
|
async function getPypi(env) {
|
||||||
// 1) live pypistats; on success refresh the D1 last-good cache.
|
// 1) live pypistats; on success refresh the D1 last-good cache.
|
||||||
try {
|
try {
|
||||||
@@ -61,17 +59,12 @@ export async function onRequest(context) {
|
|||||||
"Cache-Control": "public, max-age=60",
|
"Cache-Control": "public, max-age=60",
|
||||||
};
|
};
|
||||||
|
|
||||||
const web = { human: 0, agent: 0, bot: 0, window_days: WINDOW_DAYS };
|
const web = { human: 0, agent: 0, bot: 0 };
|
||||||
try {
|
try {
|
||||||
if (env.DB) {
|
if (env.DB) {
|
||||||
const since = new Date(Date.now() - WINDOW_DAYS * 86400000)
|
|
||||||
.toISOString()
|
|
||||||
.slice(0, 10);
|
|
||||||
const { results } = await env.DB.prepare(
|
const { results } = await env.DB.prepare(
|
||||||
"SELECT klass, SUM(n) AS total FROM visits WHERE day >= ?1 GROUP BY klass",
|
"SELECT klass, SUM(n) AS total FROM visits GROUP BY klass",
|
||||||
)
|
).all();
|
||||||
.bind(since)
|
|
||||||
.all();
|
|
||||||
for (const row of results || []) {
|
for (const row of results || []) {
|
||||||
if (row.klass in web) web[row.klass] = Number(row.total) || 0;
|
if (row.klass in web) web[row.klass] = Number(row.total) || 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user