Skip to content
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

4.8 optimization #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion controllers/v1/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ module.exports = class Solutions extends Abstract {
* @method
* @name verifyLink
* @param {Object} req - requested data.
* @param {String} req.params._id - solution Id
* @param {String} req.params._id - solution link
* @returns {Array}
*/

Expand Down
7 changes: 4 additions & 3 deletions controllers/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,11 @@ module.exports = class Users extends Abstract {

let currentMaximumCountOfRequiredEntities = 0;
let requiredEntities = new Array;
let roleArray = req.query.role.split(",");

// Calculate required entities for each of the role and send the output of the role which has maximum length.
for (let roleCount = 0; roleCount < req.query.role.split(",").length; roleCount++) {
const eachRole = req.query.role.split(",")[roleCount];
for (let roleCount = 0; roleCount < roleArray.length; roleCount++) {
const eachRole = roleArray[roleCount];
const entitiesMappingData =
await usersHelper.entityTypesByLocationAndRole(
req.params._id,
Expand Down Expand Up @@ -566,7 +567,7 @@ module.exports = class Users extends Abstract {
};
}

targetedEntities.result = targetedEntity.data;
targetedEntities.result = targetedEntity.data[0];
}
}

Expand Down
13 changes: 10 additions & 3 deletions models/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ module.exports = {
name: "programs",
schema: {
externalId: String,
name: String,
description: String,
name: {
type : String,
index : true
},
description: {
type : String,
index : true
},
owner: String,
createdBy: String,
updatedBy: String,
Expand All @@ -20,7 +26,8 @@ module.exports = {
components: ["json"],
isAPrivateProgram : {
default : false,
type : Boolean
type : Boolean,
index : true
},
scope : {
entityType : String,
Expand Down
15 changes: 12 additions & 3 deletions models/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ module.exports = {
schema: {
externalId: String,
isReusable: Boolean,
name: String,
description: String,
name: {
type : String,
index : true
},
description: {
type : String,
index : true
},
author: String,
parentSolutionId: "ObjectId",
resourceType: Array,
Expand Down Expand Up @@ -87,7 +93,10 @@ module.exports = {
},
criteriaLevelReport : Boolean,
license:Object,
link: String,
link: {
type : String,
index : true
},
minNoOfSubmissionsRequired: {
type: Number,
default: 1
Expand Down
4 changes: 3 additions & 1 deletion models/user-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module.exports = {
schema: {
code: {
type: String,
required: true
required: true,
index: true,
unique: true
},
title: {
type: String,
Expand Down
49 changes: 28 additions & 21 deletions module/programs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,29 +498,36 @@ module.exports = class ProgramsHelper {

if ( targetedPrograms.success && targetedPrograms.data && targetedPrograms.data.data.length > 0) {

for (
let targetedProgram = 0;
targetedProgram < targetedPrograms.data.data.length;
targetedProgram ++
) {

let currentTargetedProgram = targetedPrograms.data.data[targetedProgram];

if( currentTargetedProgram.components.length > 0 ) {

let solutions = await solutionsHelper.solutionDocuments({
_id : { $in : currentTargetedProgram.components },
isDeleted : false,
status : constants.common.ACTIVE
},["_id"]);

if( solutions && solutions.length > 0 ) {
currentTargetedProgram["solutions"] = solutions.length;
delete currentTargetedProgram.components;
}
let componentsIds = [];
targetedPrograms.data.data.forEach(targetedProgram => {
if( targetedProgram.components.length > 0 ) {
componentsIds = componentsIds.concat(targetedProgram.components);
}
});

let solutions = await solutionsHelper.solutionDocuments({
_id : { $in : componentsIds },
isDeleted : false,
status : constants.common.ACTIVE
},["_id"]);

const solutionsIds = []
solutions.forEach(solution => solutionsIds.push(solution._id.toString()));

targetedPrograms.data.data.forEach(targetedProgram => {

if( targetedProgram.components.length > 0 ) {

let countSolutions = 0;
targetedProgram.components.forEach(component => {
if (solutionsIds.includes(component.toString())) {
countSolutions++;
}
});
targetedProgram.solutions = countSolutions;
delete targetedProgram.components;
}
}
});
}

return resolve({
Expand Down
49 changes: 20 additions & 29 deletions module/solutions/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,15 +1379,13 @@ module.exports = class SolutionsHelper {
}

let targetedSolutions = {
success: false,
success: false
};

let getTargetedSolution = true;

if ( filter === constants.common.DISCOVERED_BY_ME ) {
getTargetedSolution = false;
} else if ( solutionType === constants.common.COURSE ) {
getTargetedSolution = true;
} else if ( gen.utils.convertStringToBoolean(surveyReportPage) === true ) {
getTargetedSolution = false;
}
Expand All @@ -1405,28 +1403,25 @@ module.exports = class SolutionsHelper {
);
}

if( targetedSolutions.success ) {

if( targetedSolutions.data.data && targetedSolutions.data.data.length > 0 ) {
totalCount += targetedSolutions.data.count;
targetedSolutions.data.data.forEach(targetedSolution => {
targetedSolution.solutionId = targetedSolution._id;
targetedSolution._id = "";
if( targetedSolutions.success && targetedSolutions.data.data && targetedSolutions.data.data.length > 0 ) {
totalCount += targetedSolutions.data.count;
targetedSolutions.data.data.forEach(targetedSolution => {
targetedSolution.solutionId = targetedSolution._id;
targetedSolution._id = "";

if( solutionType !== constants.common.COURSE ) {
targetedSolution["creator"] = targetedSolution.creator ? targetedSolution.creator : "";
}

if ( solutionType === constants.common.SURVEY ) {
targetedSolution.isCreator = false;
}

mergedData.push(targetedSolution);
delete targetedSolution.type;
delete targetedSolution.externalId;
if( solutionType !== constants.common.COURSE ) {
targetedSolution["creator"] = targetedSolution.creator ? targetedSolution.creator : "";
}

});
}
if ( solutionType === constants.common.SURVEY ) {
targetedSolution.isCreator = false;
}

mergedData.push(targetedSolution);
delete targetedSolution.type;
delete targetedSolution.externalId;

});
}

if( mergedData.length > 0 ) {
Expand All @@ -1440,7 +1435,7 @@ module.exports = class SolutionsHelper {
message: constants.apiResponses.TARGETED_OBSERVATION_FETCHED,
data: {
data: mergedData,
count: totalCount,
count: totalCount
},
});
} catch (error) {
Expand Down Expand Up @@ -1681,8 +1676,8 @@ module.exports = class SolutionsHelper {
//non targeted project exist
let checkIfUserProjectExistsQuery = {
createdBy: userId,
referenceFrom: constants.common.LINK,
link: link,
referenceFrom: constants.common.LINK
};

let checkForProjectExist =
Expand Down Expand Up @@ -1735,10 +1730,6 @@ module.exports = class SolutionsHelper {
verified: false,
};

if ( link == "" ) {
throw new Error(constants.apiResponses.LINK_REQUIRED_CHECK);
}

if ( userToken == "" ) {
throw new Error(constants.apiResponses.REQUIRED_USER_AUTH_TOKEN);
}
Expand Down
29 changes: 21 additions & 8 deletions module/users/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ module.exports = class UsersHelper {
static entityTypesByLocationAndRole(stateLocationId, role) {
return new Promise(async (resolve, reject) => {
try {

let filterQuery = {
"registryDetails.code": stateLocationId,
};
Expand All @@ -601,7 +602,7 @@ module.exports = class UsersHelper {
}

const entitiesData = await entitiesHelper.entityDocuments(filterQuery, [
"_id",
"_id", "childHierarchyPath"
]);

if (!entitiesData.length > 0) {
Expand All @@ -625,24 +626,36 @@ module.exports = class UsersHelper {

let entityTypes = [];
let stateEntityExists = false;
let roleEntityType = "";

rolesDocument[0].entityTypes.forEach((roleDocument) => {
if (roleDocument.entityType === constants.common.STATE_ENTITY_TYPE) {
stateEntityExists = true;
}

if (entitiesData[0].childHierarchyPath.includes(roleDocument.entityType)) {
roleEntityType = roleDocument.entityType;
}

});

let entityTypeIndex =
entitiesData[0].childHierarchyPath.findIndex(path => path === roleEntityType);

if (stateEntityExists) {
entityTypes = [constants.common.STATE_ENTITY_TYPE];
} else {
let entitiesMappingForm = await this.entitiesMappingForm(
entitiesData[0]._id,
rolesDocument[0]._id
);

entitiesMappingForm.result.forEach((entitiesMappingData) => {
entityTypes.push(entitiesMappingData.field);
});
for (
let pointerToChildHierarchy = 0;
pointerToChildHierarchy < entityTypeIndex + 1;
pointerToChildHierarchy++
) {

let entityType = entitiesData[0].childHierarchyPath[pointerToChildHierarchy];
entityTypes.push(entityType);
}

}

return resolve({
Expand Down