lib/tasks/dc_cleanup.rake in drg_cms-0.5.10.7 vs lib/tasks/dc_cleanup.rake in drg_cms-0.5.10.10
- old
+ new
@@ -45,9 +45,25 @@
ActionDispatch::Session::MongoidStore::Session.where(:updated_at.lt => 1.week.ago).delete
DcSite.collection.database.command(eval: "db.runCommand ( { compact: 'sessions' } )" )
end
###########################################################################
+ desc 'Clears mongodb session documents created by web robots'
+ task :clear_sessions_from_robots, [:name] => :environment do |t, args|
+# This should remove all sessions documents created by web robots
+# ActionDispatch::Session::MongoidStore::Session.where('$where' => 'this.created_at == this.updated_at').limit(1000).each do |doc|
+ n = 0
+ ActionDispatch::Session::MongoidStore::Session.batch_size(1000).all.each do |doc|
+ if (doc.created_at == doc.updated_at)
+ doc.delete
+ p "Deleted #{n}" if (n+=1)%1000 == 0
+ end
+ end
+ p "Deleted #{n}"
+ DcSite.collection.database.command(eval: "db.runCommand ( { compact: 'sessions' } )" )
+ end
+
+###########################################################################
desc 'Removes all statistics from dc_visits up to specified date and save them to visits_date.json.'
task :clear_visits, [:name] => :environment do |t, args|
date = read_input("Enter end date (yyyymmdd): ")
return unless date.size == 8