Skip to content

Commit

Permalink
changed the update logic for how new_entries are determined. This was…
Browse files Browse the repository at this point in the history
… necessary because we don't want to need all feed entries in memory to compare against to see if a feed is new. The way it's done is a bit of a hack to get around the fact that not all feeds (as in the xml online) actually include published dates for their entries
  • Loading branch information
pauldix committed Feb 5, 2009
1 parent 9f0c4b4 commit 4d32296
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/feedzirra/feed_utilities.rb
Expand Up @@ -26,7 +26,7 @@ def has_new_entries?

def update_from_feed(feed)
self.new_entries += find_new_entries_for(feed)
self.entries += self.new_entries
self.entries.unshift(*self.new_entries)

updated! if UPDATABLE_ATTRIBUTES.any? { |name| update_attribute(feed, name) }
end
Expand All @@ -46,7 +46,13 @@ def updated!
end

def find_new_entries_for(feed)
feed.entries.inject([]) { |result, entry| result << entry unless existing_entry?(entry); result }
latest_entry = self.entries.first
found_new_entries = []
feed.entries.each do |entry|
break if entry.url == latest_entry.url
found_new_entries << entry
end
found_new_entries
end

def existing_entry?(test_entry)
Expand Down
2 changes: 1 addition & 1 deletion spec/feedzirra/feed_utilities_spec.rb
Expand Up @@ -125,8 +125,8 @@
@new_entry.url = "http://pauldix.net/new.html"
@new_entry.published = (Time.now + 10).to_s
@feed.entries << @old_entry
@updated_feed.entries << @old_entry
@updated_feed.entries << @new_entry
@updated_feed.entries << @old_entry
end

it "should update last-modified from the latest entry date" do
Expand Down

0 comments on commit 4d32296

Please sign in to comment.