CartoDB/cartodb20

View on GitHub
services/user-mover/import_user.rb

Summary

Maintainability
F
4 days
Test Coverage

Class ImportJob has 79 methods (exceeds 20 allowed). Consider refactoring.
Open

    class ImportJob
      include CartoDB::DataMover::Utils
      include CartoDB::DataMover::LegacyFunctions
      attr_reader :logger

Severity: Major
Found in services/user-mover/import_user.rb - About 1 day to fix

    File import_user.rb has 653 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'pg'
    require 'redis'
    require 'yaml'
    require 'json'
    require 'logger'
    Severity: Major
    Found in services/user-mover/import_user.rb - About 1 day to fix

      Method import_user has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

            def import_user
              begin
                if @options[:metadata]
                  check_user_exists_redis
                  check_user_exists_postgres
      Severity: Minor
      Found in services/user-mover/import_user.rb - About 5 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

      Method import_user has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def import_user
              begin
                if @options[:metadata]
                  check_user_exists_redis
                  check_user_exists_postgres
      Severity: Major
      Found in services/user-mover/import_user.rb - About 2 hrs to fix

        Method import_org has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def import_org
                import_metadata("org_#{@organization_id}_metadata.sql") if @options[:metadata]
                create_org_role(@pack_config['users'][0]['database_name']) # Create org role for the original org
                @pack_config['groups'].each do |group|
                  create_role(group['database_role'])
        Severity: Minor
        Found in services/user-mover/import_user.rb - About 1 hr to fix

          Method initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def initialize(options)
                  default_options = { data: true, metadata: true, set_banner: true, update_metadata: true }
                  @options = default_options.merge(options)
                  @config = CartoDB::DataMover::Config.config
                  @logger = @options[:logger] || default_logger
          Severity: Minor
          Found in services/user-mover/import_user.rb - About 1 hr to fix

            Method process_user has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def process_user
                    @target_username = @pack_config['user']['username']
                    @target_userid = @pack_config['user']['id']
                    @import_log[:id] = @pack_config['user']['username']
                    @target_port = ENV['USER_DB_PORT'] || @config[:dbport]
            Severity: Minor
            Found in services/user-mover/import_user.rb - About 1 hr to fix

              Method process_user has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def process_user
                      @target_username = @pack_config['user']['username']
                      @target_userid = @pack_config['user']['id']
                      @import_log[:id] = @pack_config['user']['username']
                      @target_port = ENV['USER_DB_PORT'] || @config[:dbport]
              Severity: Minor
              Found in services/user-mover/import_user.rb - About 45 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

              Method update_database_retries has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                    def update_database_retries(userid, username, db_host, db_name, retries = 1)
              Severity: Minor
              Found in services/user-mover/import_user.rb - About 35 mins to fix

                Method update_metadata_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def update_metadata_user(target_dbhost)
                        user_model = ::User.find(username: @target_username)
                        orig_dbhost = user_model.database_host
                        changed_metadata = false
                        begin
                Severity: Minor
                Found in services/user-mover/import_user.rb - About 35 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

                Method rollback_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def rollback_user
                        if @options[:metadata]
                          rollback_metadata("user_#{@target_userid}_metadata_undo.sql")
                          rollback_redis("user_#{@target_userid}_metadata_undo.redis")
                        end
                Severity: Minor
                Found in services/user-mover/import_user.rb - About 35 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

                Method import_org has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                      def import_org
                        import_metadata("org_#{@organization_id}_metadata.sql") if @options[:metadata]
                        create_org_role(@pack_config['users'][0]['database_name']) # Create org role for the original org
                        @pack_config['groups'].each do |group|
                          create_role(group['database_role'])
                Severity: Minor
                Found in services/user-mover/import_user.rb - About 35 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

                Method rollback_org has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def rollback_org
                        db = @pack_config['users'][0]['database_name']
                        @pack_config['users'].each do |user|
                          @logger.info("Rolling back metadata for org user #{user['id']}..")
                          ImportJob.new(file: @path + "user_#{user['id']}.json",
                Severity: Minor
                Found in services/user-mover/import_user.rb - 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

                Method create_user_api_key_roles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def create_user_api_key_roles(user_id)
                        Carto::User.find(user_id).api_keys.select(&:needs_setup?).each do |k|
                          begin
                            k.role_creation_queries.each { |q| superuser_user_pg_conn.query(q) }
                          rescue PG::Error => e
                Severity: Minor
                Found in services/user-mover/import_user.rb - 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

                Method target_dbname has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                      def target_dbname
                        return @pack_config['users'][0]['database_name'] if @pack_config['organization']
                
                        @target_userid = @pack_config['user']['id']
                        if org_import?
                Severity: Minor
                Found in services/user-mover/import_user.rb - 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

                There are no issues that match your filters.

                Category
                Status