Skip to content

Commit

Permalink
update panoptes_membership_client.rb to create insert query using arr…
Browse files Browse the repository at this point in the history
…ay.new vs times.map per hound
  • Loading branch information
yuenmichelle1 committed Apr 10, 2024
1 parent 0d4e2a6 commit 2c335ad
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/panoptes_membership_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def user_memberships(user_group_id, user_ids)

def memberships_insert_query(memberships_to_create)
# Values is part of sql query will look like ($1, $2, $3, $4), ($5, $6, $7, $8), ..etc..
values = memberships_to_create.length.times.map { |i| "($#{(4 * i) + 1}, $#{(4 * i) + 2}, $#{(4 * i) + 3}, $#{(4 * i) + 4})" }.join(',')

values = Array.new(memberships_to_create.length) do |i|
"($#{(4 * i) + 1}, $#{(4 * i) + 2}, $#{(4 * i) + 3}, $#{(4 * i) + 4})"
end.join(',')
"INSERT INTO memberships (user_id, user_group_id, state, roles) VALUES #{values}"
end
end

0 comments on commit 2c335ad

Please sign in to comment.