Class: Dexter::IndexCreator
- Inherits:
-
Object
- Object
- Dexter::IndexCreator
- Includes:
- Logging
- Defined in:
- lib/dexter/index_creator.rb
Constant Summary
Constants included from Logging
Instance Method Summary collapse
-
#initialize(connection, indexer, new_indexes, tablespace) ⇒ IndexCreator
constructor
A new instance of IndexCreator.
-
#perform ⇒ Object
1.
Methods included from Logging
Constructor Details
#initialize(connection, indexer, new_indexes, tablespace) ⇒ IndexCreator
Returns a new instance of IndexCreator.
5 6 7 8 9 10 |
# File 'lib/dexter/index_creator.rb', line 5 def initialize(connection, indexer, new_indexes, tablespace) @connection = connection @indexer = indexer @new_indexes = new_indexes @tablespace = tablespace end |
Instance Method Details
#perform ⇒ Object
-
create lock
-
refresh existing index list
-
create indexes that still don’t exist
-
release lock
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dexter/index_creator.rb', line 16 def perform with_advisory_lock do @new_indexes.each do |index| unless index_exists?(index) statement = String.new("CREATE INDEX CONCURRENTLY ON #{@connection.quote_ident(index[:table])} (#{index[:columns].map { |c| @connection.quote_ident(c) }.join(", ")})") statement << " TABLESPACE #{@connection.quote_ident(@tablespace)}" if @tablespace log "Creating index: #{statement}" started_at = monotonic_time begin @connection.execute(statement) log "Index created: #{((monotonic_time - started_at) * 1000).to_i} ms" rescue PG::LockNotAvailable log "Could not acquire lock: #{index[:table]}" end end end end end |