some speed ups

This commit is contained in:
Ward Wouts 2005-05-10 20:51:06 +00:00
parent f4ab55fdf0
commit e827c94393

View file

@ -1,4 +1,4 @@
# $Dwarf: article.rb,v 1.111 2005/03/06 07:01:08 ward Exp $
# $Dwarf: article.rb,v 1.112 2005/03/06 11:14:28 ward Exp $
# $Source$
#
@ -90,6 +90,8 @@ private :sendka
end # class KANNTP
end # module Net
############################################################
class Article
Debuglevel = 1
@ -197,7 +199,7 @@ def preselect(subject)
end
def add(id, messid, subject, server)
@messageinfo.push(Message.new(messid, id.to_i, server, subject))
@messageinfo.push(Message.new(messid, id, server, subject))
@grouped = false
end
@ -305,7 +307,7 @@ def get_articles(cachedir=false)
# en anders een leuk regeltje aan de cache toevoegen,
# maar niet in het geheugen houden
if preselect(art[id]["subject"])
add(id, art[id]["messid"], art[id]["subject"], server)
add(id.to_i, art[id]["messid"], art[id]["subject"], server)
end
cache_add(cachedir, id, art[id]["messid"], art[id]["subject"], server)
end
@ -651,7 +653,10 @@ def group_subjects
@groups = {}
for i in (0...@messageinfo.length)
print "group subjects: #{i} #{@messageinfo[i][:subject]}\n" if Debuglevel > 3
# misschien is het wel belangrijk dat er voorkeuren in deze
# match zitten... geen idee
if @messageinfo[i][:subject] =~ /(.*)\((\d+)\/(\d+)\)(.*)/ || @messageinfo[i][:subject] =~ /(.*)\[(\d+)\/(\d+)\](.*)/
#if @messageinfo[i][:subject] =~ /(.*)[\(\[](\d+)\/(\d+)[\)\]](.*)/
j = "#{$1}#{$4} (#{$3})"
number = $2
total = $3
@ -673,7 +678,7 @@ end
def set_skip_ids(server, ids)
set = Set::IntSpan.new(ids)
set.finite or return false
set.finite? or return false
min = set.min
min != nil and min < 0 and return false
@connections[server]["skip_ids"] = set
@ -717,7 +722,10 @@ p "reading & scrubbing cache"
p Time.now
filename = "#{cachedir}/#{@group}.ripnewscache"
excludes = {}
regexp = Regexp.new('^([^\|]*)\|([^\|]*)\|(.*)')
for server in @connections.keys
first = @connections[server]["first"]
last = @connections[server]["last"]
#cache_scrub(cachedir, server)
puts " reading cache for #{server}"
puts " #{Time.now}"
@ -726,15 +734,17 @@ puts " #{Time.now}"
if FileTest.directory?( cachedir) and FileTest.file?( "#{filename}.#{server}" ) and FileTest.readable?( "#{filename}.#{server}" )
outfile = File.new("#{filename}.#{server}.new", "w") or puts "Couldn't open cachefile for writing"
File.new( "#{filename}.#{server}" ).each{ |line|
id, messid, subject = line.split("|", 3)
id_i = id.to_i
if id_i >= @connections[server]["first"] and
id_i <= @connections[server]["last"]
line =~ regexp
id_i = $1.to_i
messid = $2
subject = $3
if first <= id_i and id_i <= last
outfile.puts(line)
unless excludes[server].has_key?(id_i)
if preselect(subject)
add(id_i, messid, subject, server)
end
# XXX alle traagheid van de cache_read zit in deze regel:
@connections[server]["skip_ids"].insert(id_i)
end
end