Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- STDOUT.sync = true
- STDERR.sync = true
- require 'time'
- require 'mysql2'
- END_OF_TIME = Time.now.to_i - 14 * 86_400
- SQLS = [
- 'DELETE FROM co_block WHERE user IN(15) AND action IN(1) AND time < ?', # fire spread
- 'DELETE FROM co_block WHERE user IN(21) AND action IN(1) AND time < ?', # Water spread
- 'DELETE FROM co_block WHERE user IN(33) AND action IN(0, 1) AND time < ?', # Piston movement
- 'DELETE FROM co_block WHERE user IN(162) AND type IN(11) AND action IN(3) AND time < ?', # Creeper suicided
- 'DELETE FROM co_block WHERE wid IN(3, 8) AND type IN(32) AND action IN(3) AND time < ?' # Killed Enderman
- ].freeze
- client = Mysql2::Client.new(
- host: '127.0.0.1',
- username: 'root',
- password: '',
- database: 'database'
- )
- def query(client, sql)
- statement = client.prepare(sql)
- statement.execute(END_OF_TIME)
- rescue => e
- STDERR.puts e.message
- STDERR.puts e.backtrace.join("\n")
- end
- begin
- SQLS.each do |sql|
- query_time = Time.now
- result = query(client, sql)
- affected_rows = result.affected_rows
- elapsed_time = Time.now - query_time
- puts format('Query OK, %d rows affected (%.2f sec)', affected_rows, elapsed_time)
- end
- ensure
- client.close if client
- puts 'Disconnected'
- end
Add Comment
Please, Sign In to add comment