Permalink
Browse files

remove old topics

  • Loading branch information...
1 parent d389abb commit 94e9b9c2cb216f2a6cf8ca313a10d83d086afd5a @zh committed Nov 30, 2010
Showing with 11 additions and 0 deletions.
  1. +11 −0 webglue.rb
View
@@ -327,5 +327,16 @@ def each
throw :halt, [200, ListSubscriptions.new]
end
+ get '/admin/cleanup' do
+ protected!
+ # old topics with no subscriptions
+ ids = DB[:topics].filter(:created < (Time.now - 24*3600*7)).select(:id,:created).collect {
+ |t| t[:id] if DB[:subscriptions].filter(:topic_id=>t[:id]).count == 0 }
+ ids.delete_if {|x| x.nil?}
+ count = DB[:topics].filter(:id => ids).delete
+ content_type 'text/plain', :charset => 'utf-8'
+ throw :halt, [200, "#{count} topics deleted."]
+ end
+
end
end

0 comments on commit 94e9b9c

Please sign in to comment.