File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ class Cache {
3030 async hasLaunch ( mod : string , version : string , ip : string ) {
3131 return this . cache . has ( `launch:${ mod } :${ version } :${ ip } ` ) ;
3232 }
33+
34+ async setUniqueLaunch ( mod : string , version : string , ip : string ) {
35+ return this . cache . set ( `unique_launch:${ mod } :${ version } :${ ip } ` , 1 , "24h" ) ;
36+ }
37+
38+ async hasUniqueLaunch ( mod : string , version : string , ip : string ) {
39+ return this . cache . has ( `unique_launch:${ mod } :${ version } :${ ip } ` ) ;
40+ }
3341}
3442
3543export default async function ( fastify : FastifyInstance ) {
Original file line number Diff line number Diff line change @@ -237,6 +237,27 @@ export const plugin: FastifyPluginAsyncZod = async fastify => {
237237 await cache . setLaunch ( mod_id , mc_version_group , request . ip ) ;
238238 }
239239
240+ const hasUniqueLaunch = await cache . hasUniqueLaunch (
241+ mod_id ,
242+ mc_version_group ,
243+ request . ip
244+ ) ;
245+
246+ if ( ! hasUniqueLaunch ) {
247+ await db . collection < ModStats > ( Collections . ModStats ) . updateOne (
248+ {
249+ mod_id
250+ } ,
251+ {
252+ $inc : {
253+ [ `unique_launches.${ mc_version_group } .${ dayjs ( ) . format ( "YYYY.M.D" ) } ` ] : 1
254+ }
255+ }
256+ ) ;
257+
258+ await cache . setUniqueLaunch ( mod_id , mc_version_group , request . ip ) ;
259+ }
260+
240261 return {
241262 // NOTE: the website uses the same slug format (includes dashes)
242263 homepage : `https://blakesmods.com/${ mod ! . curseforge_slug } ` ,
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ export interface ModStats {
4545 mod_id : string ;
4646 downloads : Record < any , any > ;
4747 launches : Record < any , any > ;
48+ unique_launches : Record < any , any > ;
4849}
4950
5051export interface PageViews {
You can’t perform that action at this time.
0 commit comments