Replace additional instances of map.flatten with flat_map

This is a follow-up to https://github.com/rails/rails/pull/14240. As noted in that issue, using `flat_map` is significantly faster than `map.flatten`.

```ruby
require 'benchmark'

array = 10_000.times.map { (0..999).to_a }

Benchmark.bm 8 do |x|
  x.report('#flatten')  { array.map      { |x| x }.flatten(1) }
  x.report('#flat_map') { array.flat_map { |x| x } }
end
```
                   user     system      total        real
    #flatten   0.460000   0.030000   0.490000 (  0.529242)
    #flat_map  0.030000   0.030000   0.060000 (  0.049880)