Groups::GroupMembersController#create can produce an enormous amount of SQL queries
Per InfluxDB:
> select action, sql_count_max as counts from downsampled.rails_transaction_sql_counts_per_action where time > now() - 24h and sql_count_max > 5000 limit 10;
name: rails_transaction_sql_counts_per_action
time action counts
---- ------ ------
1485179460000000000 Projects::EnvironmentsController#index.json 10726
1485187020000000000 Projects::EnvironmentsController#index.json 10797
1485199140000000000 Projects::EnvironmentsController#index.json 10855
1485212280000000000 Projects::EnvironmentsController#index.json 10998
1485261780000000000 Groups::GroupMembersController#create 5002
1485261840000000000 Groups::GroupMembersController#create 5026
1485261900000000000 Groups::GroupMembersController#create 5055
1485261960000000000 Groups::GroupMembersController#create 5077
1485262020000000000 Groups::GroupMembersController#create 5101
1485262080000000000 Groups::GroupMembersController#create 5126
We started looking into this because we noticed a steady increase in the maximum number of SQL queries over the past few hours. Based on the above query it seems there's some kind of N+1 query problem when creating group members.