diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2010-09-12 18:31:16 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2010-09-12 18:31:16 (GMT) |
commit | d63a74e6d9341edb69dff1c4c4187e6feead43bf (patch) | |
tree | 596b59acb2ce6d82acf61489302f1b978dd59c62 | |
parent | 1ba83ea8ee06aa86d3a7a783410f4afc787bacae (diff) |
Fix html caching for channel-index and day pages
-rwxr-xr-x | cgi/channel-index.pl | 17 | ||||
-rwxr-xr-x | cgi/out.pl | 12 |
2 files changed, 22 insertions, 7 deletions
diff --git a/cgi/channel-index.pl b/cgi/channel-index.pl index 577b137..7771120 100755 --- a/cgi/channel-index.pl +++ b/cgi/channel-index.pl @@ -10,6 +10,8 @@ use Cache::FileCache; use lib 'lib'; use IrcLog qw(get_dbh gmt_today); +my $dbh = get_dbh(); + # test_calendar(); go(); @@ -19,7 +21,19 @@ sub go { my $meetings = $q->param("meetings") || 0; print "Content-Type: text/html; charset=utf-8\n\n"; - my $cache_name = $channel . '|' . $meetings . '|' . gmt_today(); + my $count = 0; + { + my $sth = $dbh->prepare_cached( + 'SELECT COUNT(*) FROM irclog WHERE day = ? AND channel = ? ' . + ($meetings ? 'AND meeting IS NOT NULL ' : '')); + $sth->execute(gmt_today(), '#' . $channel); + $sth->bind_columns(\$count); + $sth->fetch(); + $sth->finish(); + $count = 1 if $count > 0; + } + + my $cache_name = 'channel-index.pl|' . $channel . '|' . $meetings . '|' . gmt_today() . '|' . $count; my $cache = new Cache::FileCache({ namespace => 'irclog' }); my $data = $cache->get($cache_name); @@ -53,7 +67,6 @@ sub get_channel_index { # we are evil and create a calendar entry for month between the first # and last date - my $dbh = get_dbh(); my $get_dates = 'SELECT DISTINCT day FROM irclog WHERE nick IS NOT NULL '. 'AND channel = ? '. ($meetings ? 'AND meeting IS NOT NULL ' : ''). @@ -81,16 +81,16 @@ if ($channel !~ m/\A[.\w-]+\z/smx){ my $count = 0; -if (abs(date($date) - date(gmt_today())) > 1) { +if (abs(date($date) - date(gmt_today())) <= 1) { my $sth; - if ($meetings && $date != $full_date) { + if ($meetings && !($date eq $full_date)) { $sth = $dbh->prepare_cached( 'SELECT COUNT(*) FROM irclog WHERE meeting = ? AND channel = ?'); - $sth->execute($full_date, $channel); + $sth->execute($full_date, '#' . $channel); } else { $sth = $dbh->prepare_cached( 'SELECT COUNT(*) FROM irclog WHERE day = ? AND channel = ?'); - $sth->execute($date, $channel); + $sth->execute($date, '#' . $channel); } $sth->bind_columns(\$count); $sth->fetch(); @@ -98,7 +98,7 @@ if (abs(date($date) - date(gmt_today())) > 1) { } { - my $cache_key = $channel . '|' . $meetings . '|' . $full_date . '|' . $count; + my $cache_key = 'out.pl|' . $channel . '|' . $meetings . '|' . $full_date . '|' . $count; # the average #perl6 day produces 100k to 400k of HTML, so with # 50MB we have about 150 pages in the cache. Since most hits are # the "today" page and those of the last 7 days, we still get a very @@ -137,6 +137,8 @@ sub irclog_output { push @meeting_times, { meeting => $meeting, time => $time }; } + $sth->finish(); + if (@meeting_times == 1) { $full_date = $meeting_times[0]{'meeting'}; } else { |