summaryrefslogtreecommitdiff
path: root/lib/feed2imap/cache.rb
diff options
context:
space:
mode:
authorlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2006-10-23 16:21:20 +0000
committerlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2006-10-23 16:21:20 +0000
commitdd108ab5ffc959ebfaf326769e5fc74822b6647b (patch)
treeb384cddf85540a0285c792fcef66016f6e858b34 /lib/feed2imap/cache.rb
parent5eb10f0ee87a84103dd605efa16783dfeec53a54 (diff)
downloadfeed2imap-dd108ab5ffc959ebfaf326769e5fc74822b6647b.tar.gz
feed2imap-dd108ab5ffc959ebfaf326769e5fc74822b6647b.tar.bz2
feed2imap-dd108ab5ffc959ebfaf326769e5fc74822b6647b.zip
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@105 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to 'lib/feed2imap/cache.rb')
-rw-r--r--lib/feed2imap/cache.rb34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/feed2imap/cache.rb b/lib/feed2imap/cache.rb
index a101785..4687b76 100644
--- a/lib/feed2imap/cache.rb
+++ b/lib/feed2imap/cache.rb
@@ -34,13 +34,13 @@ class ItemCache
end
# Returns the really new items amongst items
- def get_new_items(id, items, always_new = false)
+ def get_new_items(id, items, always_new = false, ignore_hash = false)
if $updateddebug
puts "======================================================="
puts "GET_NEW_ITEMS FOR #{id}... (#{Time::now})"
end
@channels[id] ||= CachedChannel::new
- return @channels[id].get_new_items(items, always_new)
+ return @channels[id].get_new_items(items, always_new, ignore_hash)
end
# Commit changes to the cache
@@ -59,9 +59,16 @@ class ItemCache
def set_last_check(id, time)
@channels[id] ||= CachedChannel::new
@channels[id].lastcheck = time
+ @channels[id].failures = 0
self
end
+ # Fetching failure.
+ # returns number of failures
+ def fetch_failed(id)
+ @channels[id].fetch_failed
+ end
+
# Load the cache from an IO stream
def load(io)
begin
@@ -103,13 +110,14 @@ class CachedChannel
# 100 items should be enough for everybody, even quite busy feeds
CACHESIZE = 100
- attr_accessor :lastcheck, :items
+ attr_accessor :lastcheck, :items, :failures
def initialize
@lastcheck = Time::at(0)
@items = []
@itemstemp = [] # see below
@nbnewitems = 0
+ @failures = 0
end
# Let's explain @items and @itemstemp.
@@ -123,7 +131,7 @@ class CachedChannel
# of (old) items serialized.
# Returns the really new items amongst items
- def get_new_items(items, always_new = false)
+ def get_new_items(items, always_new = false, ignore_hash = false)
# save number of new items
@nbnewitems = items.length
# set items' cached version if not set yet
@@ -165,7 +173,10 @@ class CachedChannel
found = false
# Try to find a perfect match
@items.each do |j|
- if i.cacheditem == j
+ # note that simple_compare only CachedItem, not RSSItem, so we have to use
+ # j.simple_compare(i) and not i.simple_compare(j)
+ if (i.cacheditem == j and not ignore_hash) or
+ (j.simple_compare(i) and ignore_hash)
i.cacheditem.index = j.index
found = true
# let's put j in front of itemstemp
@@ -222,6 +233,12 @@ class CachedChannel
def nbitems
@items.length
end
+
+ def fetch_failed
+ @failures = 0 if @failures.nil?
+ @failures += 1
+ return @failures
+ end
end
# This class is the only thing kept in the cache
@@ -243,7 +260,7 @@ class CachedItem
end
def ==(other)
- if $updateddebug and @title =~ /e325/ and other.title =~ /e325/
+ if $updateddebug
puts "Comparing #{self.to_s} and #{other.to_s}:"
puts "Title: #{@title == other.title}"
puts "Link: #{@link == other.link}"
@@ -256,6 +273,11 @@ class CachedItem
(@date.nil? or other.date.nil? or @date == other.date) and @hash == other.hash
end
+ def simple_compare(other)
+ @title == other.title and @link == other.link and
+ (@creator.nil? or other.creator.nil? or @creator == other.creator)
+ end
+
def create_index
@index = ItemCache.getindex
end