From e6dba8c824063e44f7b9b330fb848c0d97b9cef2 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 7 May 2015 18:16:10 -0300 Subject: [PATCH] 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(); }); };