From 1e50f9f36497da6bbce473dd0f230867d013800f Mon Sep 17 00:00:00 2001 From: Saurabh Gupta Date: Mon, 17 Oct 2016 16:43:52 -0700 Subject: [PATCH] Use Truncate instead of delete while clearing sessions Truncate table is more efficient when deleting all table data --- lib/tasks/database.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake index ba53ab7..64478b6 100644 --- a/lib/tasks/database.rake +++ b/lib/tasks/database.rake @@ -9,7 +9,7 @@ namespace 'db:sessions' do desc "Clear the sessions table" task :clear => [:environment, 'db:load_config'] do - ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::SessionStore::Session.table_name}" + ActiveRecord::Base.connection.execute "TRUNCATE TABLE #{ActiveRecord::SessionStore::Session.table_name}" end desc "Trim old sessions from the table (default: > 30 days)"