From 04ad96730a20211411fececb364915b5d144cced Mon Sep 17 00:00:00 2001 From: ALEEF02 Date: Fri, 11 Nov 2022 08:18:34 -0500 Subject: [PATCH] Add reload games cache to admin dash --- .../main/java/ppp/db/controllers/CGames.java | 3 ++- .../main/java/ppp/staticServe/DashServe.java | 5 +++++ MavenBack/src/main/webapp/dash.html | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/MavenBack/src/main/java/ppp/db/controllers/CGames.java b/MavenBack/src/main/java/ppp/db/controllers/CGames.java index 2268e60..f72eee8 100644 --- a/MavenBack/src/main/java/ppp/db/controllers/CGames.java +++ b/MavenBack/src/main/java/ppp/db/controllers/CGames.java @@ -18,7 +18,8 @@ public class CGames { // Since our client runs on a single machine at once, it is viable to use a local cache to speed up API times. private static Map gamesCache = new ConcurrentHashMap<>(); - public static void init() { + public static void init() { // Dump (if there's games already) and fill the cache + gamesCache = new ConcurrentHashMap<>(); List games = getALLGames(); for (OGame game : games) { gamesCache.put(game.id, game); diff --git a/MavenBack/src/main/java/ppp/staticServe/DashServe.java b/MavenBack/src/main/java/ppp/staticServe/DashServe.java index 401dab6..625085a 100644 --- a/MavenBack/src/main/java/ppp/staticServe/DashServe.java +++ b/MavenBack/src/main/java/ppp/staticServe/DashServe.java @@ -12,6 +12,7 @@ import jakarta.servlet.http.HttpServletResponse; import ppp.api.GetGames; import ppp.auth.Authenticator; +import ppp.db.controllers.CGames; import ppp.db.controllers.CUser; import ppp.db.model.OUser; import ppp.meta.GlickoTwo; @@ -71,6 +72,10 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr GlickoTwo.run(); response.setStatus(200); return; + } else if (parameters.containsKey("reloadGames")) { + CGames.init(); + response.setStatus(200); + return; } response.setStatus(400); diff --git a/MavenBack/src/main/webapp/dash.html b/MavenBack/src/main/webapp/dash.html index 902c161..ab399a4 100644 --- a/MavenBack/src/main/webapp/dash.html +++ b/MavenBack/src/main/webapp/dash.html @@ -21,6 +21,24 @@ } } + function games() { + var postData = 'reloadGames=1'; + var ajaxRequest = new XMLHttpRequest(); + ajaxRequest.open('POST', '/dash'); + ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + ajaxRequest.send(postData); + ajaxRequest.onreadystatechange = function(){ + if (ajaxRequest.readyState == 4) { + if (ajaxRequest.status == 200) { + // Successfully accepted the game + console.log(JSON.parse(ajaxRequest.responseText)); + } else { + console.warn(JSON.parse(ajaxRequest.responseText).error); + } + } + } + } + @@ -29,5 +47,9 @@

Run Glicko2

+

Reload cache

+

+ +

\ No newline at end of file