Skip to content

Commit 2b0e5f5

Browse files
author
Matt Swanson
committed
Merge branch 'pr/252'
2 parents 117e6b7 + 0a6ba41 commit 2b0e5f5

7 files changed

Lines changed: 32 additions & 15 deletions

File tree

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class FindNewStories
2-
def initialize(raw_feed, last_fetched, latest_url = nil)
2+
def initialize(raw_feed, last_fetched, latest_entry_id = nil)
33
@raw_feed = raw_feed
44
@last_fetched = last_fetched
5-
@latest_url = latest_url
5+
@latest_entry_id = latest_entry_id
66
end
77

88
def new_stories
@@ -11,12 +11,12 @@ def new_stories
1111

1212
stories = []
1313
@raw_feed.entries.each do |story|
14-
break if @latest_url && story.url == @latest_url
14+
break if @latest_entry_id && story.id == @latest_entry_id
1515

16-
stories << story unless story.published &&
16+
stories << story unless story.published &&
1717
story.published < @last_fetched
1818
end
1919

2020
stories
2121
end
22-
end
22+
end

‎app/models/story.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Story < ActiveRecord::Base
44
belongs_to :feed
55

6-
validates_uniqueness_of :permalink, :scope => :feed_id
6+
validates_uniqueness_of :entry_id, scope: :feed_id
77

88
UNTITLED = "[untitled]"
99

‎app/repositories/story_repository.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def self.add(entry, feed)
99
body: extract_content(entry),
1010
is_read: false,
1111
is_starred: false,
12-
published: entry.published || Time.now)
12+
published: entry.published || Time.now,
13+
entry_id: entry.id)
1314
end
1415

1516
def self.fetch(id)

‎app/tasks/fetch_feed.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def fetch
3535

3636
private
3737
def new_entries_from(raw_feed)
38-
finder = FindNewStories.new(raw_feed, @feed.last_fetched, latest_url)
38+
finder = FindNewStories.new(raw_feed, @feed.last_fetched, latest_entry_id)
3939
finder.new_stories
4040
end
4141

42-
def latest_url
43-
return @feed.stories.first.permalink unless @feed.stories.empty?
42+
def latest_entry_id
43+
return @feed.stories.first.entry_id unless @feed.stories.empty?
4444
end
4545
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddEntryIdToStories < ActiveRecord::Migration
2+
def change
3+
add_column :stories, :entry_id, :string
4+
end
5+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class UpdateStoriesUniqueConstraints < ActiveRecord::Migration
2+
def up
3+
remove_index :stories, [:permalink, :feed_id]
4+
add_index :stories, [:entry_id, :feed_id], unique: true, length: {permalink: 767}
5+
end
6+
7+
def down
8+
remove_index :stories, [:entry_id, :feed_id]
9+
add_index :stories, [:permalink, :feed_id], unique: true, length: {permalink: 767}
10+
end
11+
end

‎spec/commands/find_new_stories_spec.rb‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
end
3737

3838
context "the feed has no timekeeping" do
39-
it "should scan until matching the last url" do
40-
new_story = stub(published: nil, url: "http://blog.com/new-story")
41-
old_story = stub(published: nil, url: "http://blog.com/old-story")
39+
it "should scan until matching the last story id" do
40+
new_story = stub(published: nil, id: "new-story")
41+
old_story = stub(published: nil, id: "old-story")
4242
feed = stub(last_modified: nil, entries: [new_story, old_story])
4343

44-
result = FindNewStories.new(feed, Time.new(2013, 1, 3), "http://blog.com/old-story").new_stories
44+
result = FindNewStories.new(feed, Time.new(2013, 1, 3), "old-story").new_stories
4545
result.should eq [new_story]
4646
end
4747
end
4848
end
49-
end
49+
end

0 commit comments

Comments
 (0)