bete cache handling and cleaning
This commit is contained in:
parent
df8c6c10d0
commit
2703d61cf2
1 changed files with 15 additions and 12 deletions
|
|
@ -8,7 +8,7 @@ require 'net/nntp'
|
|||
|
||||
class Article
|
||||
|
||||
Debuglevel = 1
|
||||
Debuglevel = 0
|
||||
|
||||
def initialize(server)
|
||||
@messids = []
|
||||
|
|
@ -30,10 +30,8 @@ def add(messid, id, subject)
|
|||
end
|
||||
|
||||
def get_articles(group, cachedir=false)
|
||||
if cachedir
|
||||
read_cache(group, cachedir)
|
||||
end
|
||||
resp, count, first, last,name = @nntp.group(group)
|
||||
resp, count, first, last, name = @nntp.group(group)
|
||||
read_cache(group, cachedir, first, last)
|
||||
range = Set::IntSpan.new("#{first}-#{last}")
|
||||
for i in (range.diff(@skip_ids).elements)
|
||||
begin
|
||||
|
|
@ -52,9 +50,7 @@ def get_articles(group, cachedir=false)
|
|||
print "whoopsie couldn't stat #{i}\n" if Debuglevel > 1
|
||||
end
|
||||
end
|
||||
if cachedir
|
||||
save_cache(group, cachedir)
|
||||
end
|
||||
end
|
||||
|
||||
def get_groups
|
||||
|
|
@ -163,8 +159,10 @@ def set_skip_ids(ids)
|
|||
return true
|
||||
end
|
||||
|
||||
def read_cache(group, cachedir)
|
||||
def read_cache(group, cachedir, first=0, last=0)
|
||||
filename = "#{cachedir}/#{group}.ripnewscache"
|
||||
excludes = {}
|
||||
@skip_ids.elements.collect!{|x| excludes[x]=true}
|
||||
if FileTest.directory?( cachedir) and FileTest.file?( filename ) and FileTest.readable?( filename )
|
||||
file = File.new( filename )
|
||||
lines = file.readlines
|
||||
|
|
@ -174,16 +172,20 @@ def read_cache(group, cachedir)
|
|||
#print "messid: #{$1}\n"
|
||||
#print "id: #{$2}\n"
|
||||
#print "subject: #{$3}\n"
|
||||
unless excludes.has_key?($2.to_i) or
|
||||
$2.to_i < first.to_i or
|
||||
$2.to_i > last.to_i
|
||||
add($1, $2, $3)
|
||||
@skip_ids.insert($2.to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_cache(group, cachedir)
|
||||
filename = "#{cachedir}/#{group}.ripnewscache"
|
||||
if FileTest.directory?( cachedir)
|
||||
if FileTest.directory?( cachedir )
|
||||
file = File.new( filename, "w" ) or print "couldn't open cachefile for writing\n"
|
||||
for i in (0...@subjects.length)
|
||||
file.print("#{@messids[i]}|#{@ids[i]}|#{@subjects[i]}\n")
|
||||
|
|
@ -355,6 +357,7 @@ end
|
|||
###############################################################
|
||||
|
||||
def subject_sort
|
||||
print "Sorting articles\n"
|
||||
sort_arr = []
|
||||
for i in (0..@subjects.length)
|
||||
print "subj sort #{@subjects[i]}\n" if Debuglevel >2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue