Just posting it here since I did not find anything on google when searching this for our rails 2 upgrade 🙂
view_context.instance_variable_get(:@_virtual_path)
Just posting it here since I did not find anything on google when searching this for our rails 2 upgrade 🙂
view_context.instance_variable_get(:@_virtual_path)
Tried a few strategies, but this seems to be the fastest:
DatabaseCleaner truncate_all: 0.8s
This: 0.2s
# fast truncation of all tables that need truncations (select is 10x faster then truncate)
# https://grosser.it/2012/07/03/rubyactiverecord-fastest-way-to-truncate-test-database/
def truncate_all_tables
config = ActiveRecord::Base.configurations[::Rails.env]
connection = ActiveRecord::Base.connection
connection.disable_referential_integrity do
connection.tables.each do |table_name|
next if connection.select_value("SELECT count(*) FROM #{table_name}") == 0
case config["adapter"]
when "mysql", "mysql2", "postgresql"
connection.execute("TRUNCATE #{table_name}")
when "sqlite", "sqlite3"
connection.execute("DELETE FROM #{table_name}")
connection.execute("DELETE FROM sqlite_sequence where name='#{table_name}'")
end
end
connection.execute("VACUUM") if config["adapter"] == "sqlite3"
end
end
In case you want to test your gem / plugin on multiple rails version:
Deletes taking to long, just take a break 🙂
(so replication can catch up/things get unblocked)
Only use save sql, there is no escapeing.
class ActiveRecord::Base
def self.slow_delete_all(condition)
count = 0
loop do
result = ActiveRecord::Base.connection.send(:delete_sql, "delete from #{table_name} where #{condition} limit 10000")
count += result
break if result == 0
sleep 1
end
count
end
end
require 'resque/tasks'
require 'resque_scheduler/tasks'
# Scheduler needs very little cpu, just start it with a worker.
desc "schedule and work, so we only need 1 dyno"
task :schedule_and_work do
if Process.fork
sh "rake environment resque:work"
else
sh "rake resque:scheduler"
Process.wait
end
end