mbroadst/rethunk

View on GitHub
lib/pool_master.js

Summary

Maintainability
F
4 days
Test Coverage

File pool_master.js has 462 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";
var util = require('util');
var events = require('events');
var Promise = require('bluebird');
var Dequeue = require('double-ended-queue');
Severity: Minor
Found in lib/pool_master.js - About 7 hrs to fix

    Function handleAllServersResponse has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    PoolMaster.prototype.handleAllServersResponse = function(servers) {
      var self = this;
      if (self._draining === true) return;
    
      // Fill all the known server from RethinkDB
    Severity: Minor
    Found in lib/pool_master.js - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function fetchServers has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    PoolMaster.prototype.fetchServers = function(useSeeds) {
      var self = this;
      var query = self._r.db('rethinkdb').table('server_status')
          .union([SEPARATOR])
          .union(self._r.db('rethinkdb').table('server_status').changes());
    Severity: Major
    Found in lib/pool_master.js - About 4 hrs to fix

      Function initPool has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      PoolMaster.prototype.initPool = function(pool) {
        var self = this;
      
        pool.on('size-diff', function(diff) {
          self._numConnections += diff;
      Severity: Major
      Found in lib/pool_master.js - About 2 hrs to fix

        Function PoolMaster has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function PoolMaster(r, options) {
          var self = this;
        
          options = options || {};
          var lineLength = options.buffer || 50;
        Severity: Major
        Found in lib/pool_master.js - About 2 hrs to fix

          Function handleAllServersResponse has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          PoolMaster.prototype.handleAllServersResponse = function(servers) {
            var self = this;
            if (self._draining === true) return;
          
            // Fill all the known server from RethinkDB
          Severity: Major
          Found in lib/pool_master.js - About 2 hrs to fix

            Function PoolMaster has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            function PoolMaster(r, options) {
              var self = this;
            
              options = options || {};
              var lineLength = options.buffer || 50;
            Severity: Minor
            Found in lib/pool_master.js - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function getConnection has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            PoolMaster.prototype.getConnection = function() {
              var self = this;
              // Find a pool with available connections
              var result;
              for (var i = 0; i < self._healthyPools.length; i++) {
            Severity: Minor
            Found in lib/pool_master.js - About 1 hr to fix

              Function getConnection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              PoolMaster.prototype.getConnection = function() {
                var self = this;
                // Find a pool with available connections
                var result;
                for (var i = 0; i < self._healthyPools.length; i++) {
              Severity: Minor
              Found in lib/pool_master.js - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid deeply nested control flow statements.
              Open

                                  if (self._options.silent !== true) {
                                    self._log('Pool connected to: ' + poolToRemove.getAddress() + ' could not be properly drained.');
                                    self._log(error.message);
                                    self._log(error.stack);
                                  }
              Severity: Major
              Found in lib/pool_master.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if (((server.network.canonical_addresses[k].host === pool.options.connection.host) ||
                               (server.network.hostname === pool.options.connection.host) ||
                              (helper.localhostAliases.hasOwnProperty(server.network.canonical_addresses[k].host) &&
                              helper.localhostAliases.hasOwnProperty(pool.options.connection.host))) &&
                              (server.network.reql_port === pool.options.connection.port)) {
                Severity: Major
                Found in lib/pool_master.js - About 45 mins to fix

                  Function fetchServers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  PoolMaster.prototype.fetchServers = function(useSeeds) {
                    var self = this;
                    var query = self._r.db('rethinkdb').table('server_status')
                        .union([SEPARATOR])
                        .union(self._r.db('rethinkdb').table('server_status').changes());
                  Severity: Minor
                  Found in lib/pool_master.js - About 25 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  PoolMaster.prototype.getNumConnections = function() {
                    var sum = 0;
                    for (var i = 0; i < this._healthyPools.length; i++) {
                      sum += this._healthyPools[i].getLength();
                    }
                  Severity: Major
                  Found in lib/pool_master.js and 1 other location - About 2 hrs to fix
                  lib/pool_master.js on lines 479..485

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 82.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                  PoolMaster.prototype.getNumAvailableConnections = function() {
                    var sum = 0;
                    for (var i = 0; i < this._healthyPools.length; i++) {
                      sum += this._healthyPools[i].getAvailableLength();
                    }
                  Severity: Major
                  Found in lib/pool_master.js and 1 other location - About 2 hrs to fix
                  lib/pool_master.js on lines 472..478

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 82.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      for (var i = 0; i < self._healthyPools.length; i++) {
                        if (self._healthyPools[i] === this) {
                          self._healthyPools.splice(i, 1);
                          self.emitStatus();
                          break;
                  Severity: Minor
                  Found in lib/pool_master.js and 1 other location - About 45 mins to fix
                  lib/pool_master.js on lines 458..464

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 50.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      for (var i = 0; i < self._healthyPools.length; i++) {
                        if (self._healthyPools[i] === this) {
                          self._healthyPools.splice(i, 1);
                          self.emitStatus();
                          break;
                  Severity: Minor
                  Found in lib/pool_master.js and 1 other location - About 45 mins to fix
                  lib/pool_master.js on lines 444..450

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 50.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    pool.on('size-diff', function(diff) {
                      self._numConnections += diff;
                      self.emit('size', self._numConnections);
                    });
                  Severity: Minor
                  Found in lib/pool_master.js and 1 other location - About 30 mins to fix
                  lib/pool_master.js on lines 413..416

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    pool.on('available-size-diff', function(diff) {
                      self._numAvailableConnections += diff;
                      self.emit('available-size', self._numAvailableConnections);
                    });
                  Severity: Minor
                  Found in lib/pool_master.js and 1 other location - About 30 mins to fix
                  lib/pool_master.js on lines 409..412

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status