From 6f1fcca5d8ecb936761f2e8770d0ec60908c90da Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Mon, 13 Jun 2022 08:30:24 +0530 Subject: [PATCH 1/6] compound index added for survey and observation --- config/dbConfig.js | 12 +++++++++++- generics/abstract.js | 3 +++ models/observations.js | 8 +++++++- models/surveys.js | 8 +++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/config/dbConfig.js b/config/dbConfig.js index bd5120b8..c0425820 100644 --- a/config/dbConfig.js +++ b/config/dbConfig.js @@ -58,11 +58,21 @@ var DB = function() { return model; }; + const runCompoundIndex = function(modelName,opts) { + if (opts && opts.length > 0) { + for ( let indexPointer = 0 ; indexPointer < opts.length ; indexPointer++ ) { + let currentIndex = opts[indexPointer]; + db.collection(modelName).createIndex(currentIndex.name, currentIndex.indexType); + } + } + } + return { database: db, createModel: createModel, ObjectId: ObjectId, - models: db.models + models: db.models, + runCompoundIndex: runCompoundIndex }; }; diff --git a/generics/abstract.js b/generics/abstract.js index 5193885b..b622546b 100644 --- a/generics/abstract.js +++ b/generics/abstract.js @@ -2,6 +2,9 @@ let Abstract = class Abstract { constructor(schema) { this.model = database.createModel(schema); this.schema = schema.name; + if ( schema.runIndex && schema.runIndex.length > 0 ) { + database.runCompoundIndex(schema.name,schema.runIndex); + } this.httpStatus = { ok: 200, diff --git a/models/observations.js b/models/observations.js index 45cb332c..7763991c 100644 --- a/models/observations.js +++ b/models/observations.js @@ -65,5 +65,11 @@ module.exports = { type : Boolean, index: true } - } + }, + runIndex: [ + { + "name" :{ createdBy: 1, solutionId: 1 }, + "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} + } + ] }; \ No newline at end of file diff --git a/models/surveys.js b/models/surveys.js index 2453686e..b3a959ca 100644 --- a/models/surveys.js +++ b/models/surveys.js @@ -43,5 +43,11 @@ module.exports = { default : false, type : Boolean } - } + }, + runIndex: [ + { + "name" :{ createdBy: 1, solutionId: 1 }, + "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} + } + ] }; \ No newline at end of file From b93de82afd8a22a615bf2e9373c93ef9663d5225 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Mon, 13 Jun 2022 13:48:57 +0530 Subject: [PATCH 2/6] rename to compoundIndex --- generics/abstract.js | 4 ++-- models/observations.js | 2 +- models/surveys.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generics/abstract.js b/generics/abstract.js index b622546b..ec482808 100644 --- a/generics/abstract.js +++ b/generics/abstract.js @@ -2,8 +2,8 @@ let Abstract = class Abstract { constructor(schema) { this.model = database.createModel(schema); this.schema = schema.name; - if ( schema.runIndex && schema.runIndex.length > 0 ) { - database.runCompoundIndex(schema.name,schema.runIndex); + if ( schema.compoundIndex && schema.compoundIndex.length > 0 ) { + database.runCompoundIndex(schema.name,schema.compoundIndex); } this.httpStatus = { diff --git a/models/observations.js b/models/observations.js index 7763991c..51c31f23 100644 --- a/models/observations.js +++ b/models/observations.js @@ -66,7 +66,7 @@ module.exports = { index: true } }, - runIndex: [ + compoundIndex: [ { "name" :{ createdBy: 1, solutionId: 1 }, "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} diff --git a/models/surveys.js b/models/surveys.js index b3a959ca..378181b7 100644 --- a/models/surveys.js +++ b/models/surveys.js @@ -44,7 +44,7 @@ module.exports = { type : Boolean } }, - runIndex: [ + compoundIndex: [ { "name" :{ createdBy: 1, solutionId: 1 }, "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} From 3a0ab86c8affce7b5b88091d5878f057d3734d45 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Mon, 13 Jun 2022 19:16:33 +0530 Subject: [PATCH 3/6] added index in submissions --- models/observationSubmissions.js | 8 +++++++- models/surveySubmissions.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/models/observationSubmissions.js b/models/observationSubmissions.js index fe851647..3d3237dc 100644 --- a/models/observationSubmissions.js +++ b/models/observationSubmissions.js @@ -90,5 +90,11 @@ module.exports = { userRoleInformation : Object, criteriaLevelReport : Boolean, userProfile : Object - } + }, + compoundIndex: [ + { + "name" :{ createdBy: 1, observationId: 1, submissionNumber:1 }, + "indexType" : { unique: true } + } + ] }; diff --git a/models/surveySubmissions.js b/models/surveySubmissions.js index daa5de52..2f120730 100644 --- a/models/surveySubmissions.js +++ b/models/surveySubmissions.js @@ -50,6 +50,12 @@ module.exports = { appInformation : Object, userRoleInformation : Object, userProfile : Object - } + }, + compoundIndex: [ + { + "name" :{ createdBy: 1, surveyId: 1 }, + "indexType" : { unique: true } + } + ] }; From ca385d85a8a7a4c9d5d22b6bb3dc1000adaea045 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Wed, 15 Jun 2022 10:51:55 +0530 Subject: [PATCH 4/6] PR comment resolved --- models/observations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/observations.js b/models/observations.js index 51c31f23..c4574842 100644 --- a/models/observations.js +++ b/models/observations.js @@ -69,7 +69,7 @@ module.exports = { compoundIndex: [ { "name" :{ createdBy: 1, solutionId: 1 }, - "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} + "indexType" : { unique: true } } ] }; \ No newline at end of file From ebb7cca02be7caa6dbef1a666973416c8738d0e4 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Wed, 15 Jun 2022 12:44:08 +0530 Subject: [PATCH 5/6] PR changes --- models/observationSubmissions.js | 2 +- models/surveySubmissions.js | 11 +++-------- models/surveys.js | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/models/observationSubmissions.js b/models/observationSubmissions.js index 3d3237dc..041332a0 100644 --- a/models/observationSubmissions.js +++ b/models/observationSubmissions.js @@ -93,7 +93,7 @@ module.exports = { }, compoundIndex: [ { - "name" :{ createdBy: 1, observationId: 1, submissionNumber:1 }, + "name" :{ entityId: 1, observationId: 1, submissionNumber:1 }, "indexType" : { unique: true } } ] diff --git a/models/surveySubmissions.js b/models/surveySubmissions.js index 2f120730..e8d7f2ee 100644 --- a/models/surveySubmissions.js +++ b/models/surveySubmissions.js @@ -4,7 +4,8 @@ module.exports = { surveyId: { type: "ObjectId", index: true, - required: true + required: true, + unique: true }, createdBy: { type: String, @@ -50,12 +51,6 @@ module.exports = { appInformation : Object, userRoleInformation : Object, userProfile : Object - }, - compoundIndex: [ - { - "name" :{ createdBy: 1, surveyId: 1 }, - "indexType" : { unique: true } - } - ] + } }; diff --git a/models/surveys.js b/models/surveys.js index 378181b7..79c07f60 100644 --- a/models/surveys.js +++ b/models/surveys.js @@ -47,7 +47,7 @@ module.exports = { compoundIndex: [ { "name" :{ createdBy: 1, solutionId: 1 }, - "indexType" : { unique: true, partialFilterExpression: { solutionId: { $exists: true }}} + "indexType" : { unique: true } } ] }; \ No newline at end of file From bfdef3ea466cc2adfb651abe64a4822faaa65e8b Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Wed, 15 Jun 2022 12:46:44 +0530 Subject: [PATCH 6/6] fix --- models/observationSubmissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/observationSubmissions.js b/models/observationSubmissions.js index 041332a0..8f2bcf0a 100644 --- a/models/observationSubmissions.js +++ b/models/observationSubmissions.js @@ -93,7 +93,7 @@ module.exports = { }, compoundIndex: [ { - "name" :{ entityId: 1, observationId: 1, submissionNumber:1 }, + "name" :{ observationId: 1, entityId: 1, submissionNumber:1 }, "indexType" : { unique: true } } ]