Skip to content

fix: batch get skills when there are many skill ids #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,16 +1139,41 @@ async function getMembersByHandles(handles) {
* @returns {Object}
*/
async function getStandSkills(ids) {

const queryBatches = [];
const skillIdArg = "&skillId=";
let queryString = "disablePagination=true";

for (const id of ids) {
const enid = encodeURIComponent(id);
// When many skill ids, the query string will exceed 2048 limit
if (queryString.length + skillIdArg.length + enid.length < 2048) {
queryString += skillIdArg + enid;
} else {
queryBatches.push(queryString);
queryString = "disablePagination=true" + skillIdArg + enid;
}
}
queryBatches.push(queryString);

const skillDataPromises = [];
const token = await m2mHelper.getM2MToken();
const res = await axios.get(`${config.API_BASE_URL}/v5/standardized-skills/skills`, {
headers: { Authorization: `Bearer ${token}` },
params: {
page: 1,
perPage: ids.length,
skillId: ids,
},
});
return res.data;
for (const batch of queryBatches) {
skillDataPromises.push(
(async () => {
const res = await axios.get(
`${config.API_BASE_URL}/v5/standardized-skills/skills?${batch}`,
{
headers: { Authorization: `Bearer ${token}` },
}
);
return res.data;
})()
);
}

const data = await Promise.all(skillDataPromises);
return _.concat(...data);
}

/**
Expand Down