diff options
Diffstat (limited to 'app/models/project_authorization.rb')
-rw-r--r-- | app/models/project_authorization.rb | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/app/models/project_authorization.rb b/app/models/project_authorization.rb index fed19a37a16..c76332b21cd 100644 --- a/app/models/project_authorization.rb +++ b/app/models/project_authorization.rb @@ -17,20 +17,6 @@ class ProjectAuthorization < ApplicationRecord .group(:project_id) end - def self.insert_authorizations(rows, per_batch = 1000) - rows.each_slice(per_batch) do |slice| - tuples = slice.map do |tuple| - tuple.map { |value| connection.quote(value) } - end - - connection.execute <<-EOF.strip_heredoc - INSERT INTO project_authorizations (user_id, project_id, access_level) - VALUES #{tuples.map { |tuple| "(#{tuple.join(', ')})" }.join(', ')} - ON CONFLICT DO NOTHING - EOF - end - end - # This method overrides its ActiveRecord's version in order to work correctly # with composite primary keys and fix the tests for Rails 6.1 # @@ -39,6 +25,12 @@ class ProjectAuthorization < ApplicationRecord def self.insert_all(attributes) super(attributes, unique_by: connection.schema_cache.primary_keys(table_name)) end + + def self.insert_all_in_batches(attributes, per_batch = 1000) + attributes.each_slice(per_batch) do |attributes_batch| + insert_all(attributes_batch) + end + end end ProjectAuthorization.prepend_mod_with('ProjectAuthorization') |