From 18628e3fe5326ce3fb22bcc086a11be4e4591b5d Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Wed, 9 Mar 2022 10:28:28 -0700 Subject: [PATCH] Speed up loading divisions on manage page --- public/scripts/manage.js | 6 +++--- routes/fetch.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/scripts/manage.js b/public/scripts/manage.js index 04ebb1c..a96bac9 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -115,7 +115,7 @@ CATEGORIES.push(new Category( CATEGORIES.push(new Category( "divisions", async function getDivisions() { - return await Data.getDivisions(); + return await (await fetch('/fetch/manage/divisions')).json(); }, async function listDivisionHeaders() { const headerRow = document.createElement('tr'); @@ -151,8 +151,8 @@ CATEGORIES.push(new Category( row.appendChild(spacerCell); const sportCell = document.createElement('td'); - Data.getSportName(division.sportID) - .then(data => sportCell.textContent = data); + let sportName = division.sport.name; + sportCell.textContent = sportName; row.appendChild(sportCell); }, async function addDivision() { diff --git a/routes/fetch.js b/routes/fetch.js index fddaefe..28a98ea 100644 --- a/routes/fetch.js +++ b/routes/fetch.js @@ -126,4 +126,14 @@ router.get('/submit', async function(req, res, next) { } }); +router.get('/manage/divisions', async function (req, res, next) { + const data = await divisions.retrieve(); + + for(const division of data) { + division.sport = await sports.getFromID(division.sportID); + } + + res.json(data); +}); + module.exports = router; \ No newline at end of file