diff --git a/lib/seek/permissions/policy_based_authorization.rb b/lib/seek/permissions/policy_based_authorization.rb index 8c70780dab..57b83f73a0 100644 --- a/lib/seek/permissions/policy_based_authorization.rb +++ b/lib/seek/permissions/policy_based_authorization.rb @@ -260,7 +260,7 @@ def update_lookup_table_for_all_users f = ActiveRecord::Base.connection.quote(false) # Insert in batches of 10 - ([0] + User.pluck(:id)).each_slice(bulk_insert_batch_size) do |batch| + ([0] + User.pluck(:id)).each_slice(Seek::Util.bulk_insert_batch_size) do |batch| sql = %(INSERT INTO #{self.class.lookup_table_name} (user_id, asset_id, can_view ,can_edit, can_download, can_manage, can_delete) VALUES #{batch.map { |user_id| "(#{user_id}, #{id}, #{f}, #{f}, #{f}, #{f}, #{f})" }.join(', ')};) @@ -424,33 +424,7 @@ def lookup_count private - # determines the batch size for bulk inserts, as sqlite3 below version 3.7.11 doesn't handle it and requires a size - # of 1 - def bulk_insert_batch_size - @bulk_insert_batch_size ||= begin - default_size=10 - if database_type =='sqlite3' && !sqlite3_supports_bulk_inserts - Rails.logger.info("Sqlite3 version < 3.7.11 detected, so using single rather than bulk inserts") - 1 - else - default_size - end - end - end - # whether the sqlite3 version can support bulk inserts, needs to be 3.7.11 or greater - def sqlite3_supports_bulk_inserts - Gem::Version.new(sqlite3_version) >= Gem::Version.new('3.7.11') - end - - # the version of the current sqlite3 database - def sqlite3_version - @sqlite3_version ||= ActiveRecord::Base.connection.select_one('SELECT SQLITE_VERSION()').values[0] - end - - def database_type - ActiveRecord::Base.connection.instance_values['config'][:adapter] - end # Note, nil user means ALL users, not guest user def update_lookup(permission, user = nil, overwrite = true) diff --git a/lib/seek/util.rb b/lib/seek/util.rb index 6af4e83695..90eb2ed1e2 100644 --- a/lib/seek/util.rb +++ b/lib/seek/util.rb @@ -112,5 +112,33 @@ def self.doiable_asset_types persistent_classes.select(&:supports_doi?).sort_by(&:name) end end + + # determines the batch size for bulk inserts, as sqlite3 below version 3.7.11 doesn't handle it and requires a size + # of 1 + def self.bulk_insert_batch_size + @@bulk_insert_batch_size ||= begin + default_size=10 + if database_type =='sqlite3' && !sqlite3_supports_bulk_inserts + Rails.logger.info("Sqlite3 version < 3.7.11 detected, so using single rather than bulk inserts") + 1 + else + default_size + end + end + end + + # whether the sqlite3 version can support bulk inserts, needs to be 3.7.11 or greater + def self.sqlite3_supports_bulk_inserts + Gem::Version.new(sqlite3_version) >= Gem::Version.new('3.7.11') + end + + # the version of the current sqlite3 database + def self.sqlite3_version + @@sqlite3_version ||= ActiveRecord::Base.connection.select_one('SELECT SQLITE_VERSION()').values[0] + end + + def self.database_type + ActiveRecord::Base.connection.instance_values['config'][:adapter] + end end end