@@ -429,6 +429,43 @@ async def selectRankedPlayers(request: Request, response: Response):
429429
430430 return xquery
431431
432+ @router .get (
433+ "/surftimer/selectRankedPlayer" ,
434+ name = "Select Ranked Players" ,
435+ tags = ["ck_playerrank" ],
436+ )
437+ async def selectRankedPlayer (request : Request , response : Response , steamid32 : str ):
438+ """`char[] sql_selectRankedPlayer = ....`"""
439+ tic = time .perf_counter ()
440+
441+ # Check if data is cached in Redis
442+ cache_key = f"selectRankedPlayer"
443+ cached_data = get_cache (cache_key )
444+ if cached_data is not None :
445+ print (f"[Redis] Loaded '{ cache_key } ' ({ time .perf_counter () - tic :0.4f} s)" )
446+ return JSONResponse (
447+ status_code = status .HTTP_200_OK , content = json .loads (cached_data )
448+ )
449+
450+ xquery = selectQuery (surftimer .queries .sql_selectRankedPlayer .format (steamid32 ))
451+ # xquery = []
452+
453+ if len (xquery ) > 0 :
454+ xquery = xquery
455+ else :
456+ response .status_code = status .HTTP_404_NOT_FOUND
457+ xquery = {}
458+ xquery ["xtime" ] = time .perf_counter () - tic
459+
460+ toc = time .perf_counter ()
461+
462+ print (f"Execution time { toc - tic :0.4f} " )
463+
464+ # Cache the data in Redis
465+ set_cache (cache_key , xquery )
466+
467+ return xquery
468+
432469
433470@router .get (
434471 "/surftimer/countRankedPlayers" ,
@@ -590,3 +627,36 @@ async def selectUnknownPlayerProfile(
590627 set_cache (cache_key , xquery )
591628
592629 return xquery
630+
631+ @router .put (
632+ "/surftimer/updatePlayerConnections" ,
633+ name = "Update Player Connections" ,
634+ tags = ["ck_playerrank" ],
635+ )
636+ async def updatePlayerConnections (
637+ request : Request ,
638+ response : Response ,
639+ steamid32 : str ,
640+ ):
641+ """```UPDATE ck_playerrank SET connections = connections + 1 WHERE steamid = '%s';```"""
642+ tic = time .perf_counter ()
643+
644+ sql = surftimer .queries .sql_updatePlayerConnections .format (steamid32 )
645+ xquery = insertQuery (sql )
646+
647+ content_data = {"updated" : xquery , "xtime" : time .perf_counter () - tic }
648+ if xquery < 1 :
649+ response .body = json .dumps (content_data ).encode ('utf-8' )
650+ response .headers ['content-type' ] = 'application/json'
651+ response .status_code = status .HTTP_304_NOT_MODIFIED
652+ return response
653+
654+ # Prepare the response
655+ toc = time .perf_counter ()
656+ print (f"Execution time { toc - tic :0.4f} " )
657+
658+ response .body = json .dumps (content_data ).encode ('utf-8' )
659+ response .headers ['content-type' ] = 'application/json'
660+ response .status_code = status .HTTP_200_OK
661+ return response
662+
0 commit comments