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