change cacheing to a file per server model
This commit is contained in:
parent
cf1c476d54
commit
dfd4648b01
1 changed files with 38 additions and 33 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#################################
|
#################################
|
||||||
#
|
#
|
||||||
# $Dwarf: article.rb,v 1.72 2003/07/13 10:38:53 ward Exp $
|
# $Dwarf: article.rb,v 1.73 2003/07/13 11:28:32 ward Exp $
|
||||||
# $Source$
|
# $Source$
|
||||||
#
|
#
|
||||||
# article.rb
|
# article.rb
|
||||||
|
|
@ -113,10 +113,10 @@ def get_articles(cachedir=false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
read_cache(cachedir)
|
read_cache(cachedir)
|
||||||
for server in @connections.keys
|
# for server in @connections.keys
|
||||||
print "############################################################\n"
|
# print "############################################################\n"
|
||||||
print "skip_ids #{server}: #{@connections[server]["skip_ids"].run_list}\n"
|
# print "skip_ids #{server}: #{@connections[server]["skip_ids"].run_list}\n"
|
||||||
end
|
# end
|
||||||
for server in @connections.keys
|
for server in @connections.keys
|
||||||
print " reading articles from server: #{server}\n"
|
print " reading articles from server: #{server}\n"
|
||||||
range = Set::IntSpan.new("#{@connections[server]["first"]}-#{@connections[server]["last"]}")
|
range = Set::IntSpan.new("#{@connections[server]["first"]}-#{@connections[server]["last"]}")
|
||||||
|
|
@ -155,8 +155,8 @@ def get_articles(cachedir=false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
headerlines += subj_lines.length
|
headerlines += subj_lines.length
|
||||||
if headerlines >= 10000
|
if headerlines >= 10000 # hmmm, dit lijkt niet te werken...
|
||||||
save_cache(cachedir)
|
save_cache(cachedir, server)
|
||||||
headerlines = 0
|
headerlines = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -166,7 +166,7 @@ def get_articles(cachedir=false)
|
||||||
del_server(server)
|
del_server(server)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
save_cache(cachedir)
|
save_cache(cachedir, server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -528,48 +528,53 @@ def read_cache(cachedir)
|
||||||
for server in @connections.keys
|
for server in @connections.keys
|
||||||
excludes[server] = {}
|
excludes[server] = {}
|
||||||
@connections[server]["skip_ids"].elements.collect!{|x| excludes[server][x]=true}
|
@connections[server]["skip_ids"].elements.collect!{|x| excludes[server][x]=true}
|
||||||
end
|
if FileTest.directory?( cachedir) and FileTest.file?( "#{filename}.#{server}" ) and FileTest.readable?( "#{filename}.#{server}" )
|
||||||
if FileTest.directory?( cachedir) and FileTest.file?( filename ) and FileTest.readable?( filename )
|
file = File.new( "#{filename}.#{server}" )
|
||||||
file = File.new( filename )
|
lines = file.readlines
|
||||||
lines = file.readlines
|
lines.collect{|line|
|
||||||
lines.collect{|line|
|
# id | messageid | subject
|
||||||
if line =~ /^(\d+)\|(.*?)\|(.*?)\|(.*)$/
|
if line =~ /^(\d+)\|(.*?)\|(.*)$/
|
||||||
if @connections.has_key?($3)
|
unless excludes.has_key?(server) and excludes[server].has_key?($1.to_i) or
|
||||||
unless excludes.has_key?($3) and excludes[$3].has_key?($1.to_i) or
|
$1.to_i < @connections[server]["first"].to_i or
|
||||||
$1.to_i < @connections[$3]["first"].to_i or
|
$1.to_i > @connections[server]["last"].to_i
|
||||||
$1.to_i > @connections[$3]["last"].to_i
|
add($2, $1, server, $3)
|
||||||
add($2, $1, $3, $4)
|
@connections[server]["skip_ids"].insert($1.to_i)
|
||||||
@connections[$3]["skip_ids"].insert($1.to_i)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
}
|
file.close
|
||||||
file.close
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_cache(cachedir)
|
def save_cache(cachedir, server)
|
||||||
filename = "#{cachedir}/#{@group}.ripnewscache"
|
filename = "#{cachedir}/#{@group}.ripnewscache"
|
||||||
if FileTest.directory?( cachedir )
|
if FileTest.directory?( cachedir )
|
||||||
file = File.new( "#{filename}.new", "w" ) or print "couldn't open cachefile for writing\n"
|
file = File.new( "#{filename}.#{server}.new", "w" ) or print "couldn't open cachefile for writing\n"
|
||||||
cache = []
|
print "Updating cache...\n"
|
||||||
|
# cache = []
|
||||||
|
# for i in (0...@subjects.length)
|
||||||
|
# cache.push("#{@ids[i]}|#{@messids[i]}|#{@servers[i]}|#{@subjects[i]}\n")
|
||||||
|
# end
|
||||||
|
# cache.sort!
|
||||||
|
# file.print cache
|
||||||
for i in (0...@subjects.length)
|
for i in (0...@subjects.length)
|
||||||
cache.push("#{@ids[i]}|#{@messids[i]}|#{@servers[i]}|#{@subjects[i]}\n")
|
if @servers[i] == server
|
||||||
|
file.print "#{@ids[i]}|#{@messids[i]}|#{@subjects[i]}\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
cache.sort!
|
|
||||||
file.print cache
|
|
||||||
file.close
|
file.close
|
||||||
if ( File.move("#{filename}.new", filename) )
|
if ( File.move("#{filename}.#{server}.new", "#{filename}.#{server}") )
|
||||||
print "Cache updated\n"
|
print "Cache updated for #{server}\n"
|
||||||
else
|
else
|
||||||
print "Couldn't update cache\n"
|
print "Couldn't update #{server} cache\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
|
|
||||||
# a bas64 decoder...
|
# a base64 decoder...
|
||||||
def decode64(str)
|
def decode64(str)
|
||||||
string = ''
|
string = ''
|
||||||
for line in str.split("\n")
|
for line in str.split("\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue