[Debtags-commits] [svn] r1457 -
central-database/branches/alioth/webfrontend
Enrico Zini
enrico at costa.debian.org
Mon Oct 31 18:39:23 UTC 2005
Author: enrico
Date: Mon Oct 31 18:39:22 2005
New Revision: 1457
Modified:
central-database/branches/alioth/webfrontend/Engine.pm
central-database/branches/alioth/webfrontend/Navigation.pm
central-database/branches/alioth/webfrontend/edit.cgi
central-database/branches/alioth/webfrontend/maint
Log:
Implemented simple cache
Modified: central-database/branches/alioth/webfrontend/Engine.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Engine.pm (original)
+++ central-database/branches/alioth/webfrontend/Engine.pm Mon Oct 31 18:39:22 2005
@@ -411,6 +411,8 @@
}
store $db, $DEBTAGS;
unlockdb();
+
+ return @tags;
}
sub removeTag ($@)
@@ -430,6 +432,8 @@
}
store $db, $DEBTAGS;
unlockdb();
+
+ return @tags;
}
##
Modified: central-database/branches/alioth/webfrontend/Navigation.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Navigation.pm (original)
+++ central-database/branches/alioth/webfrontend/Navigation.pm Mon Oct 31 18:39:22 2005
@@ -3,11 +3,15 @@
use strict;
use warnings;
use Engine;
+use Storable;
##
## Configuration options
##
+our $CACHE_BASE = './cache';
+our $PIVOT = $CACHE_BASE.'/pivot';
+
#my $release="unstable";
our $packages_min = 10; # aggregate subgroups when less than this
our $packages_max = 25; # try not to show more than this
@@ -41,6 +45,70 @@
# return -1;
#}
+##
+## Cache management
+##
+
+sub cachePath ($$)
+{
+ my ($sel_tags, $sel_words) = @_;
+ my $path = $CACHE_BASE.'/'.join('/', map { $_->name } sort { $a->name cmp $b->name } @$sel_tags);
+ my $file = '';
+ for my $w (@$sel_words)
+ {
+ $w =~ s/[^0-9A-Za-z]//g;
+ $file .= "$w-";
+ }
+ return ($path, $file.'nav.cache');
+}
+
+sub fromCache ($$)
+{
+ my ($sel_tags, $sel_words) = @_;
+ my ($path, $file) = cachePath($sel_tags, $sel_words);
+ $path .= '/'.$file;
+ my @stat = stat($path);
+ return undef if not @stat;
+ my @pstat = stat($PIVOT);
+ return undef if @pstat and $stat[9] < $pstat[9];
+ my $cached = retrieve($path);
+ @pkgs = Engine::package(@{$cached->{pkgs}});
+ @subpkgs = Engine::package(@{$cached->{subpkgs}});
+ return 1;
+}
+
+sub mkpath ($)
+{
+ my @path = split('/', $_[0]);
+ my $part;
+ for my $p (@path)
+ {
+ $part .= '/' if $part;
+ $part .= $p;
+
+ if (not -d $part)
+ {
+ mkdir $part or die "Cannot create directory $part: $!";
+ }
+ }
+}
+
+sub toCache ($$)
+{
+ my ($sel_tags, $sel_words) = @_;
+ my ($path, $file) = cachePath($sel_tags, $sel_words);
+ mkpath($path);
+ store {
+ pkgs => [ map { $_->name } @pkgs ],
+ subpkgs => [ map { $_->name } @subpkgs ],
+ }, "$path/$file";
+}
+
+sub invalidateCache ()
+{
+ open OUT, ">$PIVOT";
+ close OUT;
+}
##
## Select packages and build navigation
@@ -50,6 +118,8 @@
{
my ($sel_tags, $sel_words) = @_;
+ return if fromCache($sel_tags, $sel_words);
+
# Basic package selection
if (@$sel_tags or @$sel_words)
{
@@ -103,7 +173,7 @@
@subpkgs = grep { scalar($_->tags()) } Engine::packages();
}
- # Rearrange subgroups
+ toCache($sel_tags, $sel_words);
}
1;
Modified: central-database/branches/alioth/webfrontend/edit.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/edit.cgi (original)
+++ central-database/branches/alioth/webfrontend/edit.cgi Mon Oct 31 18:39:22 2005
@@ -13,6 +13,7 @@
use HTML::Template;
use URI::Escape;
use Engine;
+use Navigation;
##
## Configuration options
@@ -114,8 +115,11 @@
{
msg "$tag does not match a valid tag\n";
} else {
- Engine::addTag($p, $t);
- msg "Added tag $tag\n";
+ if (Engine::addTag($p, $t))
+ {
+ msg "Added tag $tag\n";
+ Navigation::invalidateCache();
+ }
}
} elsif ($par eq 'del') {
my $tag = sanitize(param($par));
@@ -124,8 +128,11 @@
{
msg "$tag does not match a valid tag\n";
} else {
- Engine::removeTag($p, $t);
- msg "Removed tag $tag\n";
+ if (Engine::removeTag($p, $t))
+ {
+ msg "Removed tag $tag\n";
+ Navigation::invalidateCache();
+ }
}
} elsif ($par eq 'fhide') {
my $fac = sanitize(param($par));
@@ -138,10 +145,13 @@
if (defined $f)
{
my @tags = grep { $p->hasTag($_) } $f->tags;
- Engine::removeTag($p, @tags);
- for my $t (@tags)
+ if (Engine::removeTag($p, @tags))
{
- msg "Removed tag %s\n", $t->name;
+ for my $t (@tags)
+ {
+ msg "Removed tag %s\n", $t->name;
+ }
+ Navigation::invalidateCache();
}
$hidden_facets{$f->name} = 1
}
Modified: central-database/branches/alioth/webfrontend/maint
==============================================================================
--- central-database/branches/alioth/webfrontend/maint (original)
+++ central-database/branches/alioth/webfrontend/maint Mon Oct 31 18:39:22 2005
@@ -6,7 +6,7 @@
sub usage ()
{
- print STDERR qq{Usage: $0 init
+ print STDERR qq{Usage: $0 init|check|dump|tagcat
};
exit 1;
}
@@ -103,6 +103,21 @@
printf "tag packages %s\n", join(', ', map { $_->{name} } $t->pkgs());
}
Engine::closeDB();
+} elsif ($cmd eq 'tagcat') {
+ Engine::openDB();
+
+ for my $p (Engine::packages())
+ {
+ my @tags = map { $_->name } $p->tags;
+ if (@tags)
+ {
+ printf "%s: %s\n", $p->name, join(', ', @tags);
+ } else {
+ printf "%s\n", $p->name;
+ }
+ }
+
+ Engine::closeDB();
} else {
usage();
}
More information about the Debtags-commits
mailing list