Skip to content

Commit 60a90f6

Browse files
author
Matt Swanson
committed
Merge branch 'pr/223'
2 parents 9a79260 + b724170 commit 60a90f6

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ To set your locale on Heroku, run `heroku config:set LOCALE=en`.
109109

110110
If you would like to translate Stringer to your preferred language, please use [LocaleApp](http://www.localeapp.com/projects/4637).
111111

112+
---
113+
114+
Clean up old read stories
115+
116+
If you are on the Heroku free plan, there is a 10k row limit so you will
117+
eventually run out of space.
118+
119+
You can clean up old stories by running:
120+
121+
`rake cleanup_old_stories`
122+
123+
By default, this removes read stories that are more than 30 days old (that
124+
are not starred). You can either run this manually or add it as a scheduled
125+
task.
126+
112127
# Development
113128

114129
Run the Ruby tests with `rspec`.

‎Rakefile‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Bundler.require
66
require "./app"
77
require_relative "./app/tasks/fetch_feeds"
88
require_relative "./app/tasks/change_password"
9+
require_relative "./app/tasks/remove_old_stories.rb"
910

1011
desc "Fetch all feeds."
1112
task :fetch_feeds do
@@ -32,6 +33,12 @@ task :change_password do
3233
ChangePassword.new.change_password
3334
end
3435

36+
desc "Clean up old stories that are read and unstarred"
37+
task :cleanup_old_stories, :number_of_days do |t, args|
38+
args.with_defaults(:number_of_days => 30)
39+
RemoveOldStories.remove!(args[:number_of_days].to_i)
40+
end
41+
3542
desc "Start server and serve JavaScript test suite at /test"
3643
task :test_js do
3744
require_relative "./spec/javascript/test_controller"

‎app/repositories/story_repository.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def self.starred(page = 1)
4242
.order("published desc").page(page).per_page(20)
4343
end
4444

45+
def self.unstarred_read_stories_older_than(num_days)
46+
Story.where(is_read: true, is_starred: false)
47+
.where('published <= ?', num_days.days.ago)
48+
end
49+
4550
def self.read_count
4651
Story.where(is_read: true).count
4752
end

‎app/tasks/remove_old_stories.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class RemoveOldStories
2+
def self.remove!(number_of_days)
3+
StoryRepository.unstarred_read_stories_older_than(number_of_days)
4+
.delete_all
5+
end
6+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'spec_helper'
2+
app_require 'tasks/remove_old_stories'
3+
4+
describe RemoveOldStories do
5+
before do
6+
@arel_mock = double('arel')
7+
@arel_mock.stub(:delete_all) { 0 }
8+
StoryRepository.stub(:unstarred_read_stories_older_than) { @arel_mock }
9+
end
10+
11+
describe '.remove!' do
12+
it 'should pass along the number of days to the story repository query' do
13+
StoryRepository.should_receive(:unstarred_read_stories_older_than).with(7)
14+
@arel_mock.should_receive(:delete_all)
15+
16+
RemoveOldStories.remove!(7)
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)