Module: KMDB::CustomRecord::ClassMethods

Defined in:
lib/kmdb/models/custom_record.rb

Instance Method Summary collapse

Instance Method Details

#clear_uncommittedObject



47
48
49
50
# File 'lib/kmdb/models/custom_record.rb', line 47

def clear_uncommitted
  # TODO: this needs to be protected by a global lock
  where('tid IS NOT NULL').delete_all
end

#commit(tid) ⇒ Object



43
44
45
# File 'lib/kmdb/models/custom_record.rb', line 43

def commit(tid)
  where(tid: tid).update_all(tid: nil)
end

#disable_indexObject



22
23
24
25
26
# File 'lib/kmdb/models/custom_record.rb', line 22

def disable_index
  connection.execute %Q{
    ALTER TABLE `#{table_name}` DISABLE KEYS;
  }
end

#enable_indexObject



28
29
30
31
32
# File 'lib/kmdb/models/custom_record.rb', line 28

def enable_index
  connection.execute %Q{
    ALTER TABLE `#{table_name}` ENABLE KEYS;
  }
end

#find_or_create(options) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/kmdb/models/custom_record.rb', line 34

def find_or_create(options)
  retries ||= 5
  where(options).first || create!(options)
rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
  $stderr.write("could not create #{self.name} with #{options.inspect}, retrying (#{retries})}\n")
  retry unless (retries -= 1).zero?
  raise
end