From 568f85f62408671db2d16a0e33e0d206effe99c4 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 7 May 2004 14:30:43 +0000 Subject: cache all tied objects git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1930 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- staticweb/article.html | 2 +- staticweb/dir.html | 8 ++++---- staticweb/header.html | 2 +- staticweb/index.html | 4 ++-- staticweb/index.pl | 41 ++++++++++++++++++++++------------------- staticweb/man.pl | 27 ++++++++++++++------------- 6 files changed, 44 insertions(+), 40 deletions(-) (limited to 'staticweb') diff --git a/staticweb/article.html b/staticweb/article.html index 1386c3d6..8c1a8260 100644 --- a/staticweb/article.html +++ b/staticweb/article.html @@ -10,7 +10,7 @@

-у金金龟穨 (PttWeb) +у金金龟穨 diff --git a/staticweb/dir.html b/staticweb/dir.html index 557438cc..071cac22 100644 --- a/staticweb/dir.html +++ b/staticweb/dir.html @@ -5,10 +5,10 @@ -呼弘地跋 -[% brdname %]狾 +у金金龟穨 | +呼弘地跋 | +[% brdname %]狾 | [% brdname %]弘地跋 -у金金场辅(big5 only)
狾嘿: [% brdname %]
@@ -36,7 +36,7 @@ [% END %]
籹丁: [% buildtime %]
-у金金龟穨 (PttWeb) +у金金龟穨 diff --git a/staticweb/header.html b/staticweb/header.html index 5dc7161b..112efd70 100644 --- a/staticweb/header.html +++ b/staticweb/header.html @@ -10,6 +10,6 @@ content="text/html; charset=[% charset %]"> - + diff --git a/staticweb/index.html b/staticweb/index.html index e13f7d2d..c0c87174 100644 --- a/staticweb/index.html +++ b/staticweb/index.html @@ -5,7 +5,7 @@ -у金金龟穨ぇ弘地跋 +у金金龟穨 » у金金龟穨ぇ弘地跋 [% FOREACH x=class %] »[% x.title %] [% END %] @@ -40,7 +40,7 @@
-у金金龟穨 (PttWeb) +у金金龟穨 diff --git a/staticweb/index.pl b/staticweb/index.pl index e6d647ba..5bfc631f 100755 --- a/staticweb/index.pl +++ b/staticweb/index.pl @@ -2,27 +2,28 @@ # $Id$ use lib qw/./; use LocalVars; -use CGI qw/:standard/; +use CGI qw/:cgi :html2/; use strict; use Template; -#use boardlist; use b2g; use DB_File; use Data::Serializer; +use vars qw/$serializer $tmpl %brdlist/; sub deserialize { my($what) = @_; - my $obj = Data::Serializer->new(serializer => 'Storable', - digester => 'MD5', - compress => 0, - ); - return $obj->deserialize($what); + $serializer = Data::Serializer->new(serializer => 'Storable', + digester => 'MD5', + compress => 0, + ) + if( !$serializer ); + return $serializer->deserialize($what); } sub main { - my($tmpl, %rh, $bid, %brd); + my(%rh, $bid) = (); if( param('gb') ){ $rh{gb} = 1; @@ -42,31 +43,32 @@ sub main charset(''); print header(); - tie %brd, 'DB_File', 'boardlist.db', O_RDONLY, 0666, $DB_HASH; + tie %brdlist, 'DB_File', 'boardlist.db', O_RDONLY, 0666, $DB_HASH + if( !%brdlist ); ($bid) = $ENV{PATH_INFO} =~ m|.*/(\d+)/$|; $bid ||= 0; $rh{isroot} = ($bid == 0); - if( !exists $brd{"class.$bid"} ){ + if( !exists $brdlist{"class.$bid"} ){ print "sorry, this bid $bid not found :("; return ; } - foreach( @{deserialize($brd{"class.$bid"})} ){ - next if( $brd{"$_.isboard"} && - !-e "$MANDATA/".$brd{"tobrdname.$_"}.'.db' ); + foreach( @{deserialize($brdlist{"class.$bid"})} ){ + next if( $brdlist{"$_.isboard"} && + !-e "$MANDATA/".$brdlist{"tobrdname.$_"}.'.db' ); - push @{$rh{dat}}, [$brd{"$_.isboard"} ? -1 : $_, - $brd{"$_.brdname"}, - $brd{"$_.title"}, + push @{$rh{dat}}, [$brdlist{"$_.isboard"} ? -1 : $_, + $brdlist{"$_.brdname"}, + $brdlist{"$_.title"}, ]; } my $path = ''; foreach( $ENV{PATH_INFO} =~ m|(\w+)|g ){ push @{$rh{class}}, {path => "$path/$_/", - title => $brd{"$_.title"}}; + title => $brdlist{"$_.title"}}; $path .= "/$_"; } $rh{exttitle} = ($rh{class} ? @@ -79,7 +81,9 @@ sub main EVAL_PERL => 0, COMPILE_EXT => '.tmpl', COMPILE_DIR => $MANCACHE, - }); + }) + if( !$tmpl ); + if( !$rh{gb} ){ $tmpl->process('index.html', \%rh); } @@ -89,7 +93,6 @@ sub main b2g::big5togb($output); print $output; } - untie %brd; } main(); diff --git a/staticweb/man.pl b/staticweb/man.pl index 661013fc..b77fcd03 100755 --- a/staticweb/man.pl +++ b/staticweb/man.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # $Id$ -use CGI qw/:standard/; +use CGI qw/:cgi :html2/; use lib qw/./; use LocalVars; use DB_File; @@ -14,15 +14,16 @@ use b2g; use POSIX; use Compress::Zlib; -use vars qw/%db $brdname $fpath $isgb %b2g/; +use vars qw/%db $brdname $fpath $isgb $tmpl/; sub main { - my($tmpl, $rh, $key); + my($rh, $key) = (); if( !(($brdname, $fpath) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)(/.*)|) || - !(tie %db, 'DB_File', - "$MANDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH) ){ + (!exists $db{$brdname} && + !tie %{$db{$brdname}}, 'DB_File', + "$MANDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH) ){ return redirect("/man.pl/$1/") if( $ENV{PATH_INFO} =~ m|^/([\w\-]+?)$| ); print header(-status => 404); @@ -48,7 +49,9 @@ sub main EVAL_PERL => 0, COMPILE_EXT => '.tmpl', COMPILE_DIR => $MANCACHE, - }); + }) + if( !$tmpl ); + if( $rh->{gb} = $isgb ){ $rh->{encoding} = 'gb2312'; $rh->{lang} = 'zh-CN'; @@ -69,8 +72,6 @@ sub main b2g::big5togb($output); print $output; } - - untie %db; } sub dirmode @@ -80,7 +81,7 @@ sub dirmode digester => 'MD5', compress => 0, ); - foreach( @{$serial->deserialize($db{$fpath}) || []} ){ + foreach( @{$serial->deserialize($db{$brdname}{$fpath}) || []} ){ $isdir = (($_->[0] =~ m|/$|) ? 1 : 0); push @{$th{dat}}, {isdir => $isdir, fn => "man.pl/$brdname$_->[0]", @@ -89,7 +90,7 @@ sub dirmode $th{tmpl} = 'dir.html'; $th{isroot} = ($fpath eq '/') ? 1 : 0; - $th{buildtime} = POSIX::ctime($db{_buildtime} || 0); + $th{buildtime} = POSIX::ctime($db{$brdname}{_buildtime} || 0); return \%th; } @@ -99,9 +100,9 @@ sub articlemode $th{tmpl} = 'article.html'; # ㄓ unzip, 璶ぃ礛穦年奔 :p - $th{content} = $db{$fpath}; + $th{content} = $db{$brdname}{$fpath}; $th{content} = Compress::Zlib::memGunzip($th{content}) - if( $db{_gzip} ); + if( $db{$brdname}{_gzip} ); $th{content} =~ s/\033\[.*?m//g; @@ -128,7 +129,7 @@ sub search($) my %result = $idx->query($th{key} = $key, MATCH_FUZZY); foreach my $t (sort { $result{$b} <=> $result{$a} } keys(%result)) { $k = $idx->getkey($t); - push @{$th{search}}, {title => $db{"title-$k"}, + push @{$th{search}}, {title => $db{$brdname}{"title-$k"}, fn => $k, score => $result{$t} / 10}; } -- cgit v1.2.3