From e6dba8c824063e44f7b9b330fb848c0d97b9cef2 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 May 2015 18:16:10 -0300 Subject: [PATCH 1/2] add indexes for commong db opperations --- lib/storage.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/storage.js b/lib/storage.js index f964126..85c3c83 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -25,12 +25,39 @@ var Storage = function(opts) { this.db = opts.db; }; +Storage.prototype._createIndexes = function() { + this.db.collection(collections.WALLETS).createIndex({ + id: 1 + }); + this.db.collection(collections.COPAYERS_LOOKUP).createIndex({ + copayerId: 1 + }); + this.db.collection(collections.TXS).createIndex({ + walletId: 1, + id: 1, + }); + this.db.collection(collections.TXS).createIndex({ + walletId: 1, + isPending: 1, + }); + this.db.collection(collections.NOTIFICATIONS).createIndex({ + walletId: 1, + id: 1, + }); + this.db.collection(collections.ADDRESSES).createIndex({ + walletId: 1 + }); + this.db.collection(collections.ADDRESSES).createIndex({ + address: 1, + }); +}; + Storage.prototype.connect = function(opts, cb) { var self = this; opts = opts || {}; - if (this.db) return cb(null); + if (this.db) return cb(); var config = opts.mongoDb || {}; mongodb.MongoClient.connect(config.uri, function(err, db) { @@ -39,8 +66,9 @@ Storage.prototype.connect = function(opts, cb) { return cb(err); } self.db = db; + self._createIndexes(); console.log('Connection established to ', config.uri); - return cb(null); + return cb(); }); }; From 82d0ba7d279c746fd4a83fcffc25355357fe1cdb Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 May 2015 18:17:18 -0300 Subject: [PATCH 2/2] remove index creation from query methods --- lib/storage.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/storage.js b/lib/storage.js index 85c3c83..8a96663 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -128,9 +128,6 @@ Storage.prototype.storeWalletAndUpdateCopayersLookup = function(wallet, cb) { }; Storage.prototype.fetchCopayerLookup = function(copayerId, cb) { - this.db.collection(collections.COPAYERS_LOOKUP).createIndex({ - copayerId: 1 - }); this.db.collection(collections.COPAYERS_LOOKUP).findOne({ copayerId: copayerId }, function(err, result) { @@ -346,9 +343,6 @@ Storage.prototype.storeAddressAndWallet = function(wallet, addresses, cb) { Storage.prototype.fetchAddress = function(address, cb) { var self = this; - this.db.collection(collections.ADDRESSES).createIndex({ - address: 1 - }); this.db.collection(collections.ADDRESSES).findOne({ address: address, }, function(err, result) {