[Debtags-commits] [svn] r1472 -
central-database/branches/alioth/webfrontend
Enrico Zini
enrico at costa.debian.org
Tue Nov 1 19:55:15 UTC 2005
Author: enrico
Date: Tue Nov 1 19:55:14 2005
New Revision: 1472
Modified:
central-database/branches/alioth/webfrontend/Engine.pm
central-database/branches/alioth/webfrontend/Navigation.pm
central-database/branches/alioth/webfrontend/Web.pm
central-database/branches/alioth/webfrontend/edit.cgi
central-database/branches/alioth/webfrontend/edittemplate.html
central-database/branches/alioth/webfrontend/index.cgi
central-database/branches/alioth/webfrontend/maint
Log:
More aggressive caching
Disable bayesian if the data isn't available for the current package
Improved formatting of long descriptions
Modified: central-database/branches/alioth/webfrontend/Engine.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Engine.pm (original)
+++ central-database/branches/alioth/webfrontend/Engine.pm Tue Nov 1 19:55:14 2005
@@ -135,6 +135,11 @@
return undef;
}
+sub hasBayesian ($)
+{
+ return -r "$PKGSTATS/".$_[0]->name;
+}
+
# Likelyhood that a tag belong to this package
sub tagLikelihood ($$)
{
Modified: central-database/branches/alioth/webfrontend/Navigation.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Navigation.pm (original)
+++ central-database/branches/alioth/webfrontend/Navigation.pm Tue Nov 1 19:55:14 2005
@@ -4,6 +4,7 @@
use warnings;
use Engine;
use Storable;
+use URI::Escape;
##
## Configuration options
@@ -29,6 +30,26 @@
# Packages displayed in subgroups
our @subpkgs;
+# Data about active facets
+our @ht_facets;
+
+# Data about packages in the current group
+our @ht_curpkgs;
+
+# Data about packages in subgroups
+our @ht_subpkgs;
+
+# Number of packages per active facet in the current view
+our %facet_counts;
+
+# Number of packages per active tag in the current view
+our %tag_counts;
+
+# Number of unselected active tags
+our $count_unselected = 0;
+
+# Number of subgroups displayed in the current view
+our $subgroup_count= 0;
##
## Generic functions
@@ -72,8 +93,15 @@
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}});
+ @pkgs = @{$cached->{pkgs}};
+ @subpkgs = @{$cached->{subpkgs}};
+ @ht_facets = @{$cached->{ht_facets}};
+ @ht_curpkgs = @{$cached->{ht_curpkgs}};
+ @ht_subpkgs = @{$cached->{ht_subpkgs}};
+ %facet_counts = %{$cached->{facet_counts}};
+ %tag_counts = %{$cached->{tag_counts}};
+ $count_unselected = $cached->{count_unselected};
+ $subgroup_count = $cached->{subgroup_count};
return 1;
}
@@ -103,8 +131,15 @@
my ($path, $file) = cachePath($sel_tags, $sel_words);
mkpath($path);
store {
- pkgs => [ map { $_->name } @pkgs ],
- subpkgs => [ map { $_->name } @subpkgs ],
+ pkgs => \@pkgs,
+ subpkgs => \@subpkgs,
+ ht_facets => \@ht_facets,
+ ht_curpkgs => \@ht_curpkgs,
+ ht_subpkgs => \@ht_subpkgs,
+ facet_counts => \%facet_counts,
+ tag_counts => \%tag_counts,
+ count_unselected => $count_unselected,
+ subgroup_count => $subgroup_count,
}, "$path/$file";
}
@@ -177,6 +212,175 @@
@subpkgs = grep { scalar($_->tags()) } Engine::packages();
}
+ ##
+ ## Build structures for HTML::Template
+ ##
+
+ # Compute tag statistics
+ if (scalar @pkgs || scalar @subpkgs)
+ {
+ for my $p (@pkgs, @subpkgs)
+ {
+ foreach my $t ($p->tags())
+ {
+ $tag_counts{$t->name} += 1;
+ $facet_counts{$t->facet->name} += 1;
+ }
+ }
+ } else {
+ for my $t (@$sel_tags)
+ {
+ $tag_counts{$t->name} = 0;
+ $facet_counts{$t->facet->name} = 0;
+ }
+ }
+
+ # Select the child tags
+ my %seen = map { $_->name => 1 } @$sel_tags;
+ my %seen_facets = map { $_->facet->name => 1 } @$sel_tags;
+
+ # Facets
+ my $count_subpkg = scalar(@subpkgs);
+ foreach my $f (Engine::facet(keys %facet_counts))
+ {
+ my @seen_tags;
+ my @tags;
+ foreach my $t ($f->tags())
+ {
+ # Skip the empty tags
+ next if not exists $tag_counts{$t->name};
+
+ if (exists $seen{$t->name})
+ {
+ push @seen_tags, {
+ NAME => $t->name,
+ SDESC => $t->sdesc,
+ LDESC => $t->ldesc,
+ COUNT => $tag_counts{$t->name},
+ REMURL =>
+ "?tags=".uri_escape(join(",", map { $_->name } grep { $_ != $t } @$sel_tags)),
+ };
+ } else {
+ ++$count_unselected;
+ if ($count_subpkg) {
+ push @tags, {
+ NAME => $t->name,
+ SDESC => $t->sdesc,
+ LDESC => $t->ldesc,
+ COUNT => $tag_counts{$t->name},
+ };
+ }
+ }
+ }
+ if (scalar(@seen_tags) or scalar(@tags))
+ {
+ push @ht_facets, {
+ NAME => $f->name,
+ SDESC => $f->sdesc,
+ LDESC => $f->ldesc,
+ SEEN => [ sort { $a->{SDESC} cmp $b->{SDESC} } @seen_tags ],
+ TAGS => [ sort { $a->{SDESC} cmp $b->{SDESC} } @tags ],
+ COUNT => $facet_counts{$f->name},
+ SELCOUNT => scalar(@seen_tags),
+ UNSCOUNT => scalar(@tags),
+ TAGCOUNT => scalar(@seen_tags) + scalar(@tags),
+ };
+ }
+ }
+ sub bystats ($$)
+ {
+ my ($a, $b) = @_;
+ return $b->{SELCOUNT} <=> $a->{SELCOUNT}
+ if $b->{SELCOUNT} != $a->{SELCOUNT};
+ return $b->{TAGCOUNT} <=> $a->{TAGCOUNT}
+ if $b->{TAGCOUNT} != $a->{TAGCOUNT};
+ return $a->{SDESC} cmp $b->{SDESC};
+ }
+ @ht_facets = sort bystats @ht_facets;
+
+# Web::timing("ht-facets");
+
+ # Package groups
+
+ # Sort packages by their tagset
+ sub bytagset ($$)
+ {
+ my ($a, $b) = @_;
+ my @atags = sort map { $_->name } $a->tags;
+ my @btags = sort map { $_->name } $b->tags;
+
+ # Smallest tagsets first
+ return scalar(@atags) <=> scalar(@btags) if (scalar(@atags) != scalar(@btags));
+
+ for my $i (0 .. $#atags)
+ {
+ return $atags[$i] cmp $btags[$i] if $atags[$i] ne $btags[$i];
+ }
+ return 0;
+ }
+
+ # Packages in subgroups
+ my $last_sec_start = 0;
+ my $lastts = '';
+ foreach my $p (sort bytagset @Navigation::pkgs)
+ {
+ my @tags = sort { $a->name() cmp $b->name() } grep { !$seen{$_->name()} } $p->tags();
+
+ if (! @tags)
+ {
+ # This is a package really in the current group
+ push @ht_curpkgs, {
+ NAME => $p->name(),
+ SDESC => $p->sdesc(),
+ LDESC => $p->ldesc(),
+ URL => "edit.cgi?pkg=".uri_escape($p->name()).
+ "&tags=".uri_escape(join(',', map{$_->name()} @$sel_tags)),
+ };
+ } else {
+ # This is a package pulled from a subgroup
+ my %data;
+
+ my $ts = join(',', @tags);
+ if ($ts ne $lastts)
+ {
+ # We are at a tagset change
+ ++$subgroup_count;
+
+ $data{SECTION} =
+ [ map { NAME=>$_->sdesc() },
+ sort { $a->sdesc cmp $b->sdesc }
+ grep { !$seen{$_->name} } @tags ];
+
+ # Initialize with current position, we'll subtract it from the start of
+ # next section when it happens
+ if (@ht_subpkgs)
+ {
+ $ht_subpkgs[$#ht_subpkgs]{LAST} = 1;
+ $ht_subpkgs[$last_sec_start]{COUNT} = @ht_subpkgs - $last_sec_start;
+ $last_sec_start = @ht_subpkgs;
+ }
+
+ $lastts = $ts;
+ }
+ $data{NAME} = $p->name();
+ $data{SDESC} = $p->sdesc();
+ $data{LDESC} = $p->ldesc();
+ $data{URL} = "edit.cgi?pkg=".uri_escape($p->name()).
+ "&tags=".uri_escape(join(',', map{$_->name()} @$sel_tags)),
+
+ push @ht_subpkgs, \%data;
+ }
+ }
+ if (@ht_subpkgs)
+ {
+ $ht_subpkgs[$#ht_subpkgs]->{LAST} = 1;
+ $ht_subpkgs[$last_sec_start]{COUNT} = @ht_subpkgs - $last_sec_start;
+ }
+
+ #msg "%d facets, %d pkgs, %d curpkgs, %d subpkgs\n", scalar(@ht_facets), scalar(@Navigation::pkgs), scalar(@ht_curpkgs), scalar @ht_subpkgs;
+
+# Web::timing("ht-packages");
+
toCache($sel_tags, $sel_words);
}
Modified: central-database/branches/alioth/webfrontend/Web.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Web.pm (original)
+++ central-database/branches/alioth/webfrontend/Web.pm Tue Nov 1 19:55:14 2005
@@ -32,7 +32,19 @@
{
my ($format, @list) = @_;
$log .= sprintf($format, @list);
- printf STDERR $format, @list;
+ printf STDERR $format, @list
+ if -t STDERR;
+}
+
+our $lasttiming = 0;
+foreach (times()) { $lasttiming += $_ }
+
+sub timing ($)
+{
+ my $timing = 0;
+ foreach (times()) { $timing += $_ }
+ msg "%s: %.2fsec\n", $_[0], $timing;
+ $lasttiming = $timing;
}
sub log_html ()
Modified: central-database/branches/alioth/webfrontend/edit.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/edit.cgi (original)
+++ central-database/branches/alioth/webfrontend/edit.cgi Tue Nov 1 19:55:14 2005
@@ -38,6 +38,7 @@
{
my ($desc) = @_;
$desc =~ s/\n+\s*\.\s*\n+/\n<\/p>\n<p>\n/mg;
+ $desc =~ s/\n +\*/<li>/mg;
return "<p>$desc</p>";
}
@@ -162,9 +163,9 @@
}
}
%has_tag = map { $_->name => 1 } $p->tags;
+ $bayesian = 0 if not $p->hasBayesian();
}
-
##
## Prepare the data for the template
##
@@ -215,7 +216,7 @@
);
if ($bayesian)
{
- my $prob = $p->tagLikelihood($t) or 0;
+ my $prob = ($p->tagLikelihood($t) or 0);
$maxprob = $prob if $prob > $maxprob;
$data{PROB} = $prob;
@@ -317,8 +318,11 @@
$template->param(FACETS => \@facets);
$template->param(UNHIDE => linkself_nohf());
-$template->param(SWITCHBAYES => linkself_nob("b=".($bayesian ? "false" : "true")));
-$template->param(SWITCHBAYESTXT => ($bayesian ? "turn prediction off" : "turn prediction on"));
+if ($p and $p->hasBayesian)
+{
+ $template->param(SWITCHBAYES => linkself_nob("b=".($bayesian ? "false" : "true")));
+ $template->param(SWITCHBAYESTXT => ($bayesian ? "turn prediction off" : "turn prediction on"));
+}
$template->param(NAVIGATE => "index.cgi?tags=$nav_tags");
$template->param(COUNT_HIDDEN => scalar keys %hidden_facets);
if (defined $p)
Modified: central-database/branches/alioth/webfrontend/edittemplate.html
==============================================================================
--- central-database/branches/alioth/webfrontend/edittemplate.html (original)
+++ central-database/branches/alioth/webfrontend/edittemplate.html Tue Nov 1 19:55:14 2005
@@ -45,7 +45,9 @@
<tmpl_if name="COUNT_HIDDEN">
<a href="<tmpl_var name='UNHIDE'>">[unhide <tmpl_var name="COUNT_HIDDEN"> facets]</a>
</tmpl_if>
- <a href="<tmpl_var name='SWITCHBAYES'>">[<tmpl_var name='SWITCHBAYESTXT'>]</a>
+ <tmpl_if name="SWITCHBAYES">
+ <a href="<tmpl_var name='SWITCHBAYES'>">[<tmpl_var name='SWITCHBAYESTXT'>]</a>
+ </tmpl_if>
</div>
<div id="curtags">
Modified: central-database/branches/alioth/webfrontend/index.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/index.cgi (original)
+++ central-database/branches/alioth/webfrontend/index.cgi Tue Nov 1 19:55:14 2005
@@ -60,6 +60,8 @@
die_on_bad_params => 0)
|| die "Could not open template";
+#Web::timing("init");
+
# Parse input values
my (@sel_tags, @sel_words);
my %hidden_facets;
@@ -101,6 +103,7 @@
for my $f (grep { Engine::hasFacet(sanitize($_)) } split(',', param($par)))
{
$hidden_facets{$f} = 1;
+# msg "Accepted HF: %s\n", $f;
}
}
elsif ($par =~ /^hf-(.+)/)
@@ -109,6 +112,7 @@
if (Engine::hasFacet($1))
{
$hidden_facets{$1} = 1;
+# msg "Accepted HF: %s\n", $1;
}
}
}
@@ -123,6 +127,8 @@
@sel_tags = Engine::tag(sort keys %tags);
}
+#Web::timing("parms");
+
#msg "Tags: %s\n", join(', ', map { $_->name } @sel_tags);
@@ -132,176 +138,19 @@
Navigation::build(@sel_tags, @sel_words);
+#Web::timing("nav");
-##
-## Build structures for HTML::Template
-##
-
+# Select the facets we want to view
my @ht_facets;
-my @ht_curpkgs;
-my @ht_subpkgs;
-
-
-# Compute tag statistics
-my %facet_counts;
-my %tag_counts;
-for my $p (@Navigation::pkgs, @Navigation::subpkgs)
+my $i = 0;
+foreach (@Navigation::ht_facets)
{
- foreach my $t ($p->tags())
- {
- $tag_counts{$t->name} += 1;
- $facet_counts{$t->facet->name} += 1;
- }
+ last if $i >= $max_facets;
+ next if not $_->{SELCOUNT} and $hidden_facets{$_->{NAME}};
+ push(@ht_facets, $_);
+ $i++;
}
-# Select the child tags
-my %seen = map { $_->name => 1 } @sel_tags;
-
-# Facets
-my $count_unselected = 0;
-my $count_subpkg = scalar(@Navigation::subpkgs);
-my $count_active_facets = 0;
-foreach my $f (Engine::facet(keys %facet_counts))
-{
- my @seen_tags;
- my @tags;
- foreach my $t ($f->tags())
- {
- # Skip the empty tags
- next if not $tag_counts{$t->name};
-
- if (exists $seen{$t->name})
- {
- push @seen_tags, {
- NAME => $t->name,
- SDESC => $t->sdesc,
- LDESC => $t->ldesc,
- COUNT => $tag_counts{$t->name},
- REMURL =>
- "?tags=".uri_escape(join(",", map { $_->name } grep { $_ != $t } @sel_tags)),
- };
- } else {
- ++$count_unselected;
- if ($count_subpkg) {
- push @tags, {
- NAME => $t->name,
- SDESC => $t->sdesc,
- LDESC => $t->ldesc,
- COUNT => $tag_counts{$t->name},
- };
- }
- }
- }
- if (scalar(@seen_tags) or scalar(@tags))
- {
- ++$count_active_facets;
- next if $hidden_facets{$f->name} and not @seen_tags;
- push @ht_facets, {
- NAME => $f->name,
- SDESC => $f->sdesc,
- LDESC => $f->ldesc,
- SEEN => [ sort { $a->{SDESC} cmp $b->{SDESC} } @seen_tags ],
- TAGS => [ sort { $a->{SDESC} cmp $b->{SDESC} } @tags ],
- COUNT => $facet_counts{$f->name},
- SELCOUNT => scalar(@seen_tags),
- UNSCOUNT => scalar(@tags),
- TAGCOUNT => scalar(@seen_tags) + scalar(@tags),
- };
- }
-}
-sub bystats ($$)
-{
- my ($a, $b) = @_;
- return $b->{SELCOUNT} <=> $a->{SELCOUNT}
- if $b->{SELCOUNT} != $a->{SELCOUNT};
- return $b->{TAGCOUNT} <=> $a->{TAGCOUNT}
- if $b->{TAGCOUNT} != $a->{TAGCOUNT};
- return $a->{SDESC} cmp $b->{SDESC};
-
-}
- at ht_facets = sort bystats @ht_facets;
- at ht_facets = @ht_facets[0 .. $max_facets - 1] if @ht_facets > $max_facets;
-
-# Package groups
-
-# Sort packages by their tagset
-sub bytagset ($$)
-{
- my ($a, $b) = @_;
- my @atags = sort map { $_->name } $a->tags;
- my @btags = sort map { $_->name } $b->tags;
-
- # Smallest tagsets first
- return scalar(@atags) <=> scalar(@btags) if (scalar(@atags) != scalar(@btags));
-
- for my $i (0 .. $#atags)
- {
- return $atags[$i] cmp $btags[$i] if $atags[$i] ne $btags[$i];
- }
- return 0;
-}
-
-# Packages in subgroups
-my $subgroup_count= 0;
-my $last_sec_start = 0;
-my $lastts = '';
-foreach my $p (sort bytagset @Navigation::pkgs)
-{
- my @tags = sort { $a->name() cmp $b->name() } grep { !$seen{$_->name()} } $p->tags();
-
- if (! @tags)
- {
- # This is a package really in the current group
- push @ht_curpkgs, {
- NAME => $p->name(),
- SDESC => $p->sdesc(),
- LDESC => $p->ldesc(),
- URL => "edit.cgi?pkg=".uri_escape($p->name()).
- "&tags=".uri_escape(join(',', map{$_->name()} @sel_tags)),
- };
- } else {
- # This is a package pulled from a subgroup
- my %data;
-
- my $ts = join(',', @tags);
- if ($ts ne $lastts)
- {
- # We are at a tagset change
- ++$subgroup_count;
-
- $data{SECTION} =
- [ map { NAME=>$_->sdesc() },
- sort { $a->sdesc cmp $b->sdesc }
- grep { !$seen{$_->name} } @tags ];
-
- # Initialize with current position, we'll subtract it from the start of
- # next section when it happens
- if (@ht_subpkgs)
- {
- $ht_subpkgs[$#ht_subpkgs]{LAST} = 1;
- $ht_subpkgs[$last_sec_start]{COUNT} = @ht_subpkgs - $last_sec_start;
- $last_sec_start = @ht_subpkgs;
- }
-
- $lastts = $ts;
- }
- $data{NAME} = $p->name();
- $data{SDESC} = $p->sdesc();
- $data{LDESC} = $p->ldesc();
- $data{URL} = "edit.cgi?pkg=".uri_escape($p->name()).
- "&tags=".uri_escape(join(',', map{$_->name()} @sel_tags)),
-
- push @ht_subpkgs, \%data;
- }
-}
-if (@ht_subpkgs)
-{
- $ht_subpkgs[$#ht_subpkgs]->{LAST} = 1;
- $ht_subpkgs[$last_sec_start]{COUNT} = @ht_subpkgs - $last_sec_start;
-}
-
-#msg "%d facets, %d pkgs, %d curpkgs, %d subpkgs\n", scalar(@ht_facets), scalar(@Navigation::pkgs), scalar(@ht_curpkgs), scalar @ht_subpkgs;
-
##
## Compile template structures
@@ -312,8 +161,8 @@
$template->param(CURHF => join(',',keys %hidden_facets));
$template->param(FACETS => \@ht_facets);
-$template->param(CURPKGS => \@ht_curpkgs);
-$template->param(SUBPKGS => \@ht_subpkgs);
+$template->param(CURPKGS => \@Navigation::ht_curpkgs);
+$template->param(SUBPKGS => \@Navigation::ht_subpkgs);
my $count_hf = keys %hidden_facets;
if ($count_hf == 1)
@@ -324,7 +173,7 @@
}
my $facet_intro;
-my $c = scalar(keys %tag_counts);
+my $c = scalar(keys %Navigation::tag_counts);
if ($c == 0)
{
$facet_intro = "There is <b>no</b> tag ";
@@ -333,11 +182,11 @@
} else {
$facet_intro = "There are <b>$c</b> tags ";
}
-if ($count_unselected == 0)
+if ($Navigation::count_unselected == 0)
{
$facet_intro .= "currently selected."
} else {
- $c = scalar keys %facet_counts;
+ $c = scalar keys %Navigation::facet_counts;
if ($c == 1)
{
$facet_intro .= "in <b>one</b> facet. ";
@@ -359,6 +208,7 @@
my $cur_facets = scalar(@ht_facets);
if ($cur_facets > 0)
{
+ my $count_active_facets = scalar(@Navigation::ht_facets);
if ($cur_facets == 1)
{
$facet_intro .= " <b>One</b> facet out of <b>$count_active_facets</b> is currently displayed.";
@@ -371,8 +221,8 @@
my $curpkgs_intro;
my $curpkgs_also;
-my $cur = scalar(@ht_curpkgs);
-my $sub = scalar(@ht_subpkgs);
+my $cur = scalar(@Navigation::ht_curpkgs);
+my $sub = scalar(@Navigation::ht_subpkgs);
if ($cur == 0)
{
$curpkgs_intro = "There is <b>no</b> package in this group. ";
@@ -396,6 +246,7 @@
$curpkgs_intro .= "<b>$sub</b> packages from ";
$cp_verb = "are";
}
+ my $subgroup_count = $Navigation::subgroup_count;
if ($subgroup_count == 1) {
$curpkgs_intro .= "<b>one</b> subgroup $cp_verb$curpkgs_also displayed below.";
} else {
Modified: central-database/branches/alioth/webfrontend/maint
==============================================================================
--- central-database/branches/alioth/webfrontend/maint (original)
+++ central-database/branches/alioth/webfrontend/maint Tue Nov 1 19:55:14 2005
@@ -118,6 +118,27 @@
}
Engine::closeDB();
+} elsif ($cmd eq 'patch-from') {
+ my $orig = shift @ARGV or usage();
+
+ Engine::openDB();
+
+ open OUT, "| tagcoll diff $orig -" or die "Cannot run tagcoll: $!";
+
+ for my $p (Engine::packages())
+ {
+ my @tags = map { $_->name } $p->tags;
+ if (@tags)
+ {
+ printf OUT "%s: %s\n", $p->name, join(', ', @tags);
+ } else {
+ printf OUT "%s\n", $p->name;
+ }
+ }
+
+ close OUT;
+
+ Engine::closeDB();
} else {
usage();
}
More information about the Debtags-commits
mailing list