Skip to content

Commit

Permalink
feat(api): Improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 6, 2023
1 parent 2de356b commit 5b887c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ router.route('/works')
console.time(`4. Sort works ${options.affiliations}`);
const publications = [];
const datasets = [];
// TODO IMPROVE PERF by replacing the forEach by a for loop
deduplicatedWorks.forEach((deduplicatedWork) => {
const deduplicatedWorksLength = deduplicatedWorks.length;
for (let i = 0; i < deduplicatedWorksLength; i += 1) {
const deduplicatedWork = deduplicatedWorks[i];
if (
(deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.type !== 'dataset')
|| (deduplicatedWork.datasource.includes('openalex') && deduplicatedWork.type !== 'dataset')
Expand All @@ -51,7 +52,7 @@ router.route('/works')
} else {
console.error(`Work not sorted : ${JSON.stringify(deduplicatedWork)}`);
}
});
}
console.timeEnd(`4. Sort works ${options.affiliations}`);
// Compute distinct types & years for facet
console.time(`5. Facet ${options.affiliations}`);
Expand Down
10 changes: 6 additions & 4 deletions server/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ const defaultDiacriticsRemovalMap = [
];

const diacriticsMap = {};
for (let i = 0; i < defaultDiacriticsRemovalMap.length; i += 1) {
const { letters } = defaultDiacriticsRemovalMap[i];
for (let j = 0; j < letters.length; j += 1) {
diacriticsMap[letters[j]] = defaultDiacriticsRemovalMap[i].base;
const defaultDiacriticsRemovalMapLength = defaultDiacriticsRemovalMap.length;
for (let i = 0; i < defaultDiacriticsRemovalMapLength; i += 1) {
const { base, letters } = defaultDiacriticsRemovalMap[i];
const lettersLength = letters.length;
for (let j = 0; j < lettersLength; j += 1) {
diacriticsMap[letters[j]] = base;
}
}

Expand Down
3 changes: 2 additions & 1 deletion server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ const groupByAffiliations = ({ options, works }) => {
// Compute distinct affiliations of works
const allAffiliationsTmp = works.reduce((deduplicatedAffiliations, work) => {
const { affiliations = [] } = work;
for (let i = 0; i < affiliations.length; i += 1) {
const affiliationsLength = affiliations.length;
for (let i = 0; i < affiliationsLength; i += 1) {
const affiliation = affiliations[i];
const normalizedAffiliation = removeDiacritics(affiliation);
if (normalizedAffiliations.some((aff) => normalizedAffiliation.includes(aff))) {
Expand Down

0 comments on commit 5b887c5

Please sign in to comment.