From 3bbd86152b2bf17fc99bf4aa95e476e2cadfb867 Mon Sep 17 00:00:00 2001 From: Kazbek <15718432+Kazbek@users.noreply.github.com> Date: Fri, 23 Apr 2021 00:14:15 +0300 Subject: [PATCH] Update lobby_api.js Trying to cache full response of lobby games api. --- routes/lobby_api.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/routes/lobby_api.js b/routes/lobby_api.js index 68bf1dde..69707791 100644 --- a/routes/lobby_api.js +++ b/routes/lobby_api.js @@ -15,6 +15,8 @@ exports = module.exports = function (req, res) { let queryResource = resource; if (resource === "countries") { queryResource = "players"; + } else if (resource === "lobby") { + queryResource = "games"; } request(process.env.LOBBY_API_URL + "/" + queryResource, function (error, response, body) { let data = []; @@ -31,11 +33,13 @@ exports = module.exports = function (req, res) { ); } - cache[queryResource] = { - pollTime: Date.now(), - data: data.length.toString() - }; - if (resource === "countries") { + + if (resource === "lobby") { + cache[resource] = { + pollTime: Date.now(), + data: body + }; + } else if (resource === "countries") { data = data.map(player => player.country); const mapData = {}; data.forEach(value => { @@ -49,7 +53,12 @@ exports = module.exports = function (req, res) { pollTime: Date.now(), data: mapData }; - } + } else { + cache[queryResource] = { + pollTime: Date.now(), + data: data.length.toString() + }; + } isFetching = false; return res.send(cache[resource].data); });