Skip to content

Commit

Permalink
refactor(back): Group all requests in Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 17, 2023
1 parent 21b0e97 commit b5f8570
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
@@ -16,18 +16,18 @@ router.route('/works')
if (!options?.affiliations) {
res.status(400).json({ message: 'You must provide at least one affiliation.' });
} else {
const data = { datasets: [], publications: [], total: {} };
const publications = await Promise.all([
const results = await Promise.all([
getBsoWorks({ options, index: process.env.VITE_BSO_PUBLICATIONS_INDEX }),
getOpenAlexPublications(options),
getBsoWorks({ options, index: process.env.VITE_BSO_DATASETS_INDEX }),
]);
publications.forEach((publication) => {
const data = { datasets: [], publications: [], total: {} };
results.slice(0, 2).forEach((publication) => {
data.publications = [...data.publications, ...publication.results];
data.total[publication.datasource] = publication.total;
});
const dataset = await getBsoWorks({ options, index: process.env.VITE_BSO_DATASETS_INDEX });
data.datasets = [...data.datasets, ...dataset.results];
data.total.dataset = dataset.total;
data.datasets = [...data.datasets, ...results[2].results];
data.total.dataset = results[2].total;
if ((Number(data.total.bso) === 0) || (Number(data.total.bso) === Number(process.env.VITE_BSO_MAX_SIZE))) {
const { count } = await getBsoCount(options);
data.total.bso = count;

0 comments on commit b5f8570

Please sign in to comment.