]> git.openstreetmap.org Git - rails.git/blob - script/cleanup
Add AND attribution per request
[rails.git] / script / cleanup
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + '/../config/environment'
4
5 last_session_id = 0
6
7 begin
8   sessions = Session.find(:all,
9                           :conditions => ["updated_at < ? and id > ?", 1.week.ago, last_session_id],
10                           :order => :id, :limit => 1000)
11
12   sessions.each do |session|
13     last_session_id = session.id
14
15     begin
16       if session[:user] and User.find(session[:user])
17         session.destroy if session.updated_at < 1.month.ago
18       else
19         session.destroy
20       end
21     rescue Exception => ex
22       puts "Invalid session #{session.session_id}: #{ex.to_s}"
23       session.destroy
24     end
25   end
26 end while sessions.length > 0
27
28 UserToken.delete_all("expiry < NOW()")
29
30 exit 0