-
Notifications
You must be signed in to change notification settings - Fork 33
enrich disintigration #478
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -940,7 +940,15 @@ async function listUsersByExternalId (externalId) { | |
context: 'listUserByExternalId', | ||
message: `response body: ${JSON.stringify(res.body)}` | ||
}) | ||
return res.body | ||
|
||
const users = res.body | ||
// populate skill data for each user skill | ||
await Promise.all(users.map(user => Promise.all(user.skills.map(async userSkill => { | ||
const skill = await getSkillById(userSkill.skillId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sande3p I think we should make a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vikasrohit the previous code was already not optimized and it loaded skills individually. The only "caching" place which I know is where we are saving matching of u-bahn skills with emsi skills https://github.com/topcoder-platform/taas-apis/blob/feature/notifications-api/scripts/emsi-mapping/index.js#L50, but I doubt that could be used as a cache here. In a nutshell, if you just would like to update TaaS API as per new Skills API, then this PR seems to be not needed, and other PR is enough https://github.com/topcoder-platform/taas-apis/pull/460/files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxceem in the previous code it didn't need to be optimized because with enrich feature users objects were already having the full data they need i.e. they already have skills names in every There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vikasrohit Got it, I've missed that in this place we didn't have loading individual skills before. Then I would suggest keep the minimal changes in this PR:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxceem Yes, I too want the PR to be as lean as possible. However, I don't think we need to wait for testing it with respect to performance, because I don't any other place in the API where we are making similar number of API calls for fetching the individual skills. So, it has very high probability of performance impact. Isn't it? Do you see any other similar level API calls in the existing code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes @vikasrohit there are such places, and they even are updated in this PR. If you check other places which are updated in this PR, there we are already requesting multiple skills by ids:
Code was refactored but the call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a picture from UI point of view: So it may happen, that when we start loading skills individually for users too. This page might become too slow. But if we optimize such calls for users, it make sense to optimize such calls in existent places too all together. See page example https://platform.topcoder-dev.com/taas/myteams/16786 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great details @maxceem. That would make it clear from QA perspective as well. @lakshmiathreya @SathyaJayabal fyi. |
||
userSkill.skill = skill | ||
})))) | ||
|
||
return users | ||
} | ||
|
||
/** | ||
|
@@ -1082,9 +1090,10 @@ async function getUserById (userId, enrich) { | |
const user = _.pick(res.body, ['id', 'handle', 'firstName', 'lastName']) | ||
|
||
if (enrich) { | ||
user.skills = (res.body.skills || []).map((skillObj) => | ||
_.pick(skillObj.skill, ['id', 'name']) | ||
) | ||
user.skills = await Promise.all((res.body.skills || []).map(async (userSkill) => { | ||
const skill = await getSkillById(userSkill.skillId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with above comment for |
||
return _.pick(skill, ['id', 'name']) | ||
})) | ||
const attributes = _.get(res, 'body.attributes', []) | ||
user.attributes = _.map(attributes, (attr) => | ||
_.pick(attr, ['id', 'value', 'attribute.id', 'attribute.name']) | ||
|
@@ -1201,18 +1210,18 @@ async function getProjectById (currentUser, id) { | |
|
||
/** | ||
* Function to search skills from v5/skills | ||
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID` | ||
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID` | ||
* | ||
* @param {Object} criteria the search criteria | ||
* @returns the request result | ||
*/ | ||
async function getTopcoderSkills (criteria) { | ||
const token = await getM2MUbahnToken() | ||
const token = await getM2MToken() | ||
try { | ||
const res = await request | ||
.get(`${config.TC_API}/skills`) | ||
.query({ | ||
skillProviderId: config.TOPCODER_SKILL_PROVIDER_ID, | ||
taxonomyId: config.TOPCODER_TAXONOMY_ID, | ||
...criteria | ||
}) | ||
.set('Authorization', `Bearer ${token}`) | ||
|
@@ -1238,7 +1247,7 @@ async function getTopcoderSkills (criteria) { | |
|
||
/** | ||
* Function to search and retrive all skills from v5/skills | ||
* - only returns skills from Topcoder Skills Provider defined by `TOPCODER_SKILL_PROVIDER_ID` | ||
* - only returns skills from Topcoder Skills API defined by `TOPCODER_TAXONOMY_ID` | ||
* | ||
* @param {Object} criteria the search criteria | ||
* @returns the request result | ||
|
@@ -1260,7 +1269,7 @@ async function getAllTopcoderSkills (criteria) { | |
* @returns the request result | ||
*/ | ||
async function getSkillById (skillId) { | ||
const token = await getM2MUbahnToken() | ||
const token = await getM2MToken() | ||
const res = await request | ||
.get(`${config.TC_API}/skills/${skillId}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
|
@@ -1270,7 +1279,7 @@ async function getSkillById (skillId) { | |
context: 'getSkillById', | ||
message: `response body: ${JSON.stringify(res.body)}` | ||
}) | ||
return _.pick(res.body, ['id', 'name']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious why we need to remove selective picking fields? Do we need any other field where this method is being consumer? |
||
return res.body | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,16 +337,13 @@ async function getTeam (currentUser, id) { | |
const teamDetail = result[0] | ||
|
||
// add job skills for result | ||
let jobSkills = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sande3p I don't understand the need of changes in this file and as previously mentioned changes for |
||
if (teamDetail && teamDetail.jobs) { | ||
for (const job of teamDetail.jobs) { | ||
if (job.skills) { | ||
const usersPromises = [] | ||
_.map(job.skills, (skillId) => { | ||
usersPromises.push(helper.getSkillById(skillId)) | ||
}) | ||
jobSkills = await Promise.all(usersPromises) | ||
job.skills = jobSkills | ||
job.skills = await Promise.all(job.skills.map(async (skillId) => { | ||
const skill = await helper.getSkillById(skillId) | ||
return _.pick(skill, ['id', 'name']) | ||
})) | ||
} | ||
} | ||
} | ||
|
@@ -385,7 +382,10 @@ async function getTeamJob (currentUser, id, jobId) { | |
|
||
if (job.skills) { | ||
result.skills = await Promise.all( | ||
_.map(job.skills, (skillId) => helper.getSkillById(skillId)) | ||
_.map(job.skills, async (skillId) => { | ||
const skill = await helper.getSkillById(skillId) | ||
return _.pick(skill, ['id', 'name']) | ||
}) | ||
) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sande3p do we need to specify Skills API swagger here? I mean now as api is extracted, we don't need its swagger here as well, right? or Am I missing something here?