diff --git a/app/models/activity_feed.rb b/app/models/activity_feed.rb index 3b2b74e3e..aec51f088 100644 --- a/app/models/activity_feed.rb +++ b/app/models/activity_feed.rb @@ -10,6 +10,7 @@ class ActivityFeed < ActiveRecord::Base serialize :data default_scope order('created_at DESC') + scope :outdated, offset(100) self.per_page = 10 diff --git a/config/schedule.rb b/config/schedule.rb index ff5f58ce7..dc4327b80 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -18,3 +18,7 @@ end every 1.day, :at => '3:30 am' do rake "pull_requests:clear", :output => 'log/pull_requests_clear.log' end + +every 1.day, :at => '3:00 am' do + rake "activity_feeds:clear", :output => 'log/activity_feeds.log' +end diff --git a/lib/tasks/activity_feeds.rake b/lib/tasks/activity_feeds.rake new file mode 100644 index 000000000..89e08b357 --- /dev/null +++ b/lib/tasks/activity_feeds.rake @@ -0,0 +1,12 @@ +namespace :activity_feeds do + desc 'Remove outdated activity feeds' + task :clear => :environment do + say "Removing outdated Activity Feed" + User.all.each do |user| + outdated = ActivityFeed.outdated + say "User #{user.uname} has #{outdated.count} outdated ActivityFeed." + user.activity_feeds.outdated.destroy_all if outdated.count > 0 + end + say "Outdated activity feeds was successfully removed." + end +end