Speed up loading for home page

main
sudoer777 2022-03-07 23:07:26 -07:00
parent b2f66b3e34
commit 36de9b3773
2 changed files with 19 additions and 3 deletions

View File

@ -60,7 +60,8 @@ async function loadTable() {
if(selectedTeamID && selectedDivisionID) {
gamesTableHeader.textContent = `Scores for ${teamDropdown.options[teamDropdown.selectedIndex].text}`;
const gamesList = await Data.getGames(selectedTeamID, selectedDivisionID, selectedSeasonID);
const requestURL = `/fetch/index/scores?team=${+selectedTeamID}&division=${+selectedDivisionID}&season=${+selectedSeasonID}`;
const gamesList = await (await fetch(requestURL)).json();
if(gamesList.length > 0) {
await setupGamesTableHeaders();
@ -77,8 +78,7 @@ async function loadTable() {
row.appendChild(scoreCell);
const opponentCell = document.createElement('td');
Data.getTeam(game.team2ID)
.then(data => opponentCell.textContent = data.name);
opponentCell.textContent = game.opponent.name;
row.appendChild(opponentCell);
const dateCell = document.createElement('td');

View File

@ -59,4 +59,20 @@ router.get('/index/dropdown', async function(req, res, next) {
}
});
router.get('/index/scores', async function (req, res, next) {
try {
const seasonID = req.query.season;
const divisionID = req.query.division;
const teamID = req.query.team;
const data = await games.retrieve(teamID, divisionID, seasonID);
for (const game of data) {
game.opponent = await teams.getFromID(game.team2ID);
}
res.json(data);
} catch(err) {
console.error("ERROR: " + err.message);
res.status(500).send("An error has occurred");
}
});
module.exports = router;