Permalink
Browse files

minor refactor

  • Loading branch information...
1 parent 49ea16e commit 92eed042068c82c33a0290f239ab46c77a162a22 @aheckmann aheckmann committed Jul 13, 2012
Showing with 42 additions and 27 deletions.
  1. +42 −27 lib/drivers/node-mongodb-native/collection.js
@@ -100,35 +100,50 @@ MongooseCollection.prototype.onClose = function () {
for (var i in NativeCollection.prototype)
(function(i){
MongooseCollection.prototype[i] = function () {
- // BENCHMARKME: is it worth caching the prototype methods? probably
- if (!this.buffer) {
- var collection = this.collection
- , args = arguments
- , self = this;
-
- process.nextTick(function(){
- var debug = self.conn.base.options.debug;
-
- if (debug) {
- if ('function' === typeof debug) {
- debug.apply(debug
- , [self.name, i].concat(utils.args(args, 0, args.length-1)));
- } else {
- console.error('\x1B[0;36mMongoose:\x1B[0m %s.%s(%s) %s %s %s'
- , self.name
- , i
- , print(args[0])
- , print(args[1])
- , print(args[2])
- , print(args[3]))
- }
- }
-
- collection[i].apply(collection, args);
- });
- } else {
+ // buffer until connected
+ // if disconnected
+ // option 1: fail fast
+ // just return errors
+ // option 2: buffer
+ // buffer cmds until reconnection
+ // if reconnection takes > optional timeout, fail buffered cmds, keep returning errors until reconnection
+ //
+ // the driver:
+ // no buffering until connected
+ // auto_reconnect buffers cmds when disconnected until reconnection
+ // if auto_reconnect = false
+ // no cmds are buffered, errors are returned
+ // but you must reconnect manually
+
+ if (this.buffer) {
this.addQueue(i, arguments);
+ return;
}
+
+ var collection = this.collection
+ , args = arguments
+ , self = this;
+
+ process.nextTick(function(){
+ var debug = self.conn.base.options.debug;
+
+ if (debug) {
+ if ('function' === typeof debug) {
+ debug.apply(debug
+ , [self.name, i].concat(utils.args(args, 0, args.length-1)));
+ } else {
+ console.error('\x1B[0;36mMongoose:\x1B[0m %s.%s(%s) %s %s %s'
+ , self.name
+ , i
+ , print(args[0])
+ , print(args[1])
+ , print(args[2])
+ , print(args[3]))
+ }
+ }
+
+ collection[i].apply(collection, args);
+ });
};
})(i);

0 comments on commit 92eed04

Please sign in to comment.