Added indexes to 'entries' and 'treatments' along with other updates (#5463)

* Added compound indexes for treatments and entries collections. Updated ensureIndex to createIndex in mongo-strage.js as ensureIndex has been deprecated. Finally, updated testing/populate.js to be compatible with more recent versions of the node driver, as well as fixing a path issue.

* Fixed missing end quote in lib/server/treatments.js. Changed all newly added double quotes to single quote to match style guide.

* Removed indexes that referenced key600.
This commit is contained in:
Adam Harrison
2020-02-05 08:27:56 +02:00
committed by GitHub
parent 82f00763d6
commit b1ec21cd3f
4 changed files with 18 additions and 7 deletions
+9 -2
View File
@@ -140,7 +140,15 @@ function storage(env, ctx) {
api.query_for = query_for; api.query_for = query_for;
api.getEntry = getEntry; api.getEntry = getEntry;
api.aggregate = require('./aggregate')({ }, api); api.aggregate = require('./aggregate')({ }, api);
api.indexedFields = [ 'date', 'type', 'sgv', 'mbg', 'sysTime', 'dateString' ]; api.indexedFields = [
'date'
, 'type'
, 'sgv'
, 'mbg'
, 'sysTime'
, 'dateString'
, { 'type' : 1, 'date' : -1, 'dateString' : 1 }
];
return api; return api;
} }
@@ -160,4 +168,3 @@ storage.queryOpts = {
// expose module // expose module
storage.storage = storage; storage.storage = storage;
module.exports = storage; module.exports = storage;
+1
View File
@@ -133,6 +133,7 @@ function storage (env, ctx) {
, 'percent' , 'percent'
, 'absolute' , 'absolute'
, 'duration' , 'duration'
, { 'eventType' : 1, 'duration' : 1, 'created_at' : 1 }
]; ];
api.remove = remove; api.remove = remove;
+3 -3
View File
@@ -37,11 +37,11 @@ function init (env, cb, forceNewConnection) {
console.log('Error connecting to MongoDB: %j - retrying in ' + timeout/1000 + ' sec', err); console.log('Error connecting to MongoDB: %j - retrying in ' + timeout/1000 + ' sec', err);
setTimeout(connect_with_retry, timeout, i+1); setTimeout(connect_with_retry, timeout, i+1);
} else if (err.message) { } else if (err.message) {
throw new Error('MongoDB connection string '+env.storageURI+' seems invalid: '+err.message) ; throw new Error('MongoDB connection string '+env.storageURI+' seems invalid: '+err.message) ;
} }
} else { } else {
console.log('Successfully established a connected to MongoDB'); console.log('Successfully established a connected to MongoDB');
var dbName = env.storageURI.split('/').pop().split('?'); var dbName = env.storageURI.split('/').pop().split('?');
dbName=dbName[0]; // drop Connection Options dbName=dbName[0]; // drop Connection Options
mongo.db = client.db(dbName); mongo.db = client.db(dbName);
@@ -66,7 +66,7 @@ function init (env, cb, forceNewConnection) {
mongo.ensureIndexes = function ensureIndexes (collection, fields) { mongo.ensureIndexes = function ensureIndexes (collection, fields) {
fields.forEach(function (field) { fields.forEach(function (field) {
console.info('ensuring index for: ' + field); console.info('ensuring index for: ' + field);
collection.ensureIndex(field, function (err) { collection.createIndex(field, { 'background': true }, function (err) {
if (err) { if (err) {
console.error('unable to ensureIndex for: ' + field + ' - ' + err); console.error('unable to ensureIndex for: ' + field + ' - ' + err);
} }
+5 -2
View File
@@ -3,19 +3,22 @@
var mongodb = require('mongodb'); var mongodb = require('mongodb');
var env = require('./../env')(); var env = require('./../env')();
var util = require('./helpers/util'); var util = require('./util');
main(); main();
function main() { function main() {
var MongoClient = mongodb.MongoClient; var MongoClient = mongodb.MongoClient;
MongoClient.connect(env.storageURI, function connected(err, db) { MongoClient.connect(env.storageURI, { "useUnifiedTopology" : true, "useNewUrlParser" : true }, function connected(err, client) {
console.log('Connecting to mongo...'); console.log('Connecting to mongo...');
if (err) { if (err) {
console.log('Error occurred: ', err); console.log('Error occurred: ', err);
throw err; throw err;
} }
var db = client.db();
populate_collection(db); populate_collection(db);
}); });
} }