A Deno-powered backend service for Plants vs. Zombies: MODDED. [Read-only GitHub mirror] docs.pvzm.net
express typescript expressjs plant deno jspvz pvzm game online backend plants-vs-zombies zombie javascript plants modded vs plantsvszombies openapi pvz noads
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Enhance featured sorting logic based on engagement data availability

Clay d994ca32 9af4fd8b

+15 -5
+15 -5
modules/routes/levels.ts
··· 294 294 295 295 let orderClause: string; 296 296 if (sort === "featured") { 297 - // Featured sort: featured levels first, then by a combined score 298 - // Score combines recency (heavily weighted) with quality (favorites > plays) 299 - // Recency weight: 1 point per day since epoch, quality: favorites * 100 + plays 300 - // This ensures recent levels rank higher than old popular ones 301 - orderClause = `featured DESC, (created_at / 86400.0 + favorites * 100 + plays) DESC`; 297 + // Check if database has mature engagement data (any level with 100+ plays) 298 + const maxPlaysResult = dbCtx.db.prepare("SELECT MAX(plays) as max_plays FROM levels").get() as { max_plays: number } | undefined; 299 + const maxPlays = maxPlaysResult?.max_plays ?? 0; 300 + const hasMatureData = maxPlays >= 100; 301 + 302 + if (hasMatureData) { 303 + // Balanced approach: recency + quality 304 + // Recency weight: 1 point per day since epoch, quality: favorites * 100 + plays 305 + orderClause = `featured DESC, (created_at / 86400.0 + favorites * 100 + plays) DESC`; 306 + } else { 307 + // New database: heavily favor recency with minimal quality impact 308 + // Recency weight: 1 point per day, quality: favorites * 10 + plays / 10 309 + // This makes recency ~100x more important than in the mature formula 310 + orderClause = `featured DESC, (created_at / 86400.0 + favorites * 10 + plays / 10.0) DESC`; 311 + } 302 312 } else { 303 313 const orderColumn = sort === "recent" ? "created_at" : sort === "favorites" ? "favorites" : "plays"; 304 314 orderClause = `${orderColumn} ${orderDirection}, id ${orderDirection}`;