Repository: rails/rails
File: activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb (Ruby)

Code before:

          def reset
            backfill

            reset_sqls = @tables.values.filter_map do |data|
              next unless data.sequence && (data.max_value || data.min_value)
              reset_sequence_sql(data.sequence, data.max_value, data.min_value)
            end

            @adapter.internal_batch_exec_query(reset_sqls, "SCHEMA")
          end

          private
            def backfill
              backfill_sequences_with_primary_keys
              backfill_sequences_with_uuids
              backfill_max_values
              backfill_min_values
            end

            def backfill_sequences_with_primary_keys
              tables_without_sequences = @tables.select do |table, data|
                !data.column || !data.sequence
              end.keys

              return unless tables_without_sequences.any?

              sql = primary_key_column_and_sequence_sql(tables_without_sequences)
              primary_key_column_and_sequences = @adapter.internal_exec_query(sql, "SCHEMA")

              primary_key_column_and_sequences.rows.each do |table, column, namespace, sequence|
                table = table.delete_prefix('"').delete_suffix('"')
                @tables[table].column = column
                @tables[table].sequence = PostgreSQL::Name.new(namespace, sequence) if sequence
              end
            end

            def backfill_sequences_with_uuids
              tables_without_sequences = @tables.select do |table, data|
                !data.column || !data.sequence
              end.keys

              return unless tables_without_sequences.any?

              sql = uuid_column_and_sequence_sql(tables_without_sequences)
              uuid_column_and_sequences = @adapter.internal_exec_query(sql, "SCHEMA")

              uuid_column_and_sequences.rows.each do |table, column, namespace, sequence|
                table = table.delete_prefix('"').delete_suffix('"')
                @tables[table].column = column
                @tables[table].sequence = PostgreSQL::Name.new(namespace, sequence) if sequence

Review comment (suggestion):
```suggestion
              return if tables_without_sequences.empty?
```

I like `empty?` over `any?` because `empty?` is a length check where `any?` iterates, but not blocking

Code after:

          def reset
            backfill

            reset_sqls = @tables.values.filter_map do |data|
              next unless data.sequence && (data.max_value || data.min_value)
              reset_sequence_sql(data.sequence, data.max_value, data.min_value)
            end

            @adapter.execute_batch(reset_sqls, "SCHEMA")
          end

          private
            def backfill
              backfill_sequences_with_primary_keys
              backfill_sequences_with_uuids
              backfill_max_values
              backfill_min_values
            end

            def backfill_sequences_with_primary_keys
              tables_without_sequences = @tables.select do |table, data|
                !data.column || !data.sequence
              end.keys

              return if tables_without_sequences.none?

              sql = primary_key_column_and_sequence_sql(tables_without_sequences)
              primary_key_column_and_sequences = @adapter.exec_query(sql, "SCHEMA")

              primary_key_column_and_sequences.rows.each do |table, column, namespace, sequence|
                table = table.delete_prefix('"').delete_suffix('"')
                @tables[table].column = column
                @tables[table].sequence = PostgreSQL::Name.new(namespace, sequence) if sequence
              end
            end

            def backfill_sequences_with_uuids
              tables_without_sequences = @tables.select do |table, data|
                !data.column || !data.sequence
              end.keys

              return if tables_without_sequences.none?

              sql = uuid_column_and_sequence_sql(tables_without_sequences)
              uuid_column_and_sequences = @adapter.exec_query(sql, "SCHEMA")

              uuid_column_and_sequences.rows.each do |table, column, namespace, sequence|
                table = table.delete_prefix('"').delete_suffix('"')
                @tables[table].column = column
                @tables[table].sequence = PostgreSQL::Name.new(namespace, sequence) if sequence