[Debtags-commits] [svn] r1441 - central-database/branches/alioth/webfrontend

Enrico Zini enrico at costa.debian.org
Sun Oct 30 13:46:04 UTC 2005


Author: enrico
Date: Sun Oct 30 13:46:00 2005
New Revision: 1441

Modified:
   central-database/branches/alioth/webfrontend/Engine.pm
   central-database/branches/alioth/webfrontend/browsetemplate.html
   central-database/branches/alioth/webfrontend/index.cgi
Log:
Tested creating a storable index for pkg<->tags relationships

Modified: central-database/branches/alioth/webfrontend/Engine.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Engine.pm	(original)
+++ central-database/branches/alioth/webfrontend/Engine.pm	Sun Oct 30 13:46:00 2005
@@ -1,6 +1,7 @@
 package Engine;
 
 use GDBM_File;
+use Storable;
 use Carp;
 
 ##
@@ -16,9 +17,9 @@
 # Layout of a package hash
 # {
 #       name => package name
-# 	sdesc => short description
-# 	ldesc => long description
-# 	tags => [ tag names ]
+#		sdesc => short description
+#		ldesc => long description
+#		tags => [ tag names ]
 # }
 
 # Layout of a facet hash
@@ -32,9 +33,9 @@
 # Layout of a tag hash
 # Value: {
 #       name => tag name
-# 	sdesc => short description
-# 	ldesc => long description
-# 	packages => [ package names ]
+#		sdesc => short description
+#		ldesc => long description
+#		packages => [ package names ]
 # }
 
 
@@ -45,6 +46,7 @@
 our %packages;
 our %facets;
 our %tags;
+our $db;
 
 our $tied = 0;
 
@@ -59,6 +61,7 @@
 	tie %packages, 'GDBM_File', $BASEDIR.'/packages.gdbm', &GDBM_READER, 0640;
 	tie %facets, 'GDBM_File', $BASEDIR.'/facets.gdbm', &GDBM_READER, 0640;
 	tie %tags, 'GDBM_File', $BASEDIR.'/tags.gdbm', &GDBM_READER, 0640;
+	$db = retrieve('debtags.store');
 	$tied = 1;
 }
 
@@ -71,6 +74,7 @@
 	undef %facets;
 	untie %tags;
 	undef %tags;
+	undef $db;
 	$tied = 0;
 }
 
@@ -89,6 +93,7 @@
 	tie %p, 'GDBM_File', $BASEDIR.'/packages.gdbm', &GDBM_READER, 0640;
 	tie %f, 'GDBM_File', $BASEDIR.'/facets.gdbm', &GDBM_READER, 0640;
 	tie %t, 'GDBM_File', $BASEDIR.'/tags.gdbm', &GDBM_READER, 0640;
+	$db = retrieve('debtags.store');
 
 	%packages = %p;
 	%facets = %f;
@@ -105,6 +110,7 @@
 	%p = %packages;
 	%f = %facets;
 	%t = %tags;
+	store $db, 'debtags.store';
 }
 
 # Get the list of package names
@@ -437,6 +443,8 @@
 	close IN;
 }
 
+use Storable;
+
 # Wipe the database and recreate it from the given package database, vocabulary
 # and tag database
 sub init ($$$)
@@ -456,6 +464,52 @@
 	print STDERR "Initializing tag data\n";
 	resyncTags($tags);
 
+	print STDERR "Creating experimental index\n";
+	my %db = (
+		pkgs => {},
+		tags => {},
+	);
+	sub mktag ($);
+	sub mkpkg ($)
+	{
+		my ($pkg) = @_;
+#		print STDERR "Want pkg $pkg.\n";
+		if (not exists $db{pkgs}{$pkg})
+		{
+#			print STDERR "Create pkg $pkg.\n";
+			my %pkg = ( name => $pkg );
+			$db{pkgs}{$pkg} = \%pkg;
+			$pkg{tags} = [map { mktag($_) } @{getPackage($pkg)->{tags}}];
+		}
+#		print STDERR "Return pkg $pkg.\n";
+		return $db{pkgs}{$pkg}
+		
+	}
+	sub mktag ($)
+	{
+		my ($tag) = @_;
+#		print STDERR "Want tag $tag.\n";
+		if (not exists $db{tags}{$tag})
+		{
+#			print STDERR "Create tag $tag.\n";
+			my %tag = ( name => $tag );
+			$db{tags}{$tag} = \%tag;
+			$tag{pkgs} = [map { mkpkg($_) } @{getTag($tag)->{packages}}];
+		}
+#		print STDERR "Return tag $tag.\n";
+		return $db{tags}{$tag}
+	}
+	my $i = 0;
+	my $count = scalar(keys %packages);
+	for my $pkg (packages())
+	{
+		printf "%d/$d\n", ++$i, $count;
+		mkpkg($pkg);
+	}
+
+	print STDERR "Writing experimental index\n";
+	store \%db, 'debtags.store';
+
 	print STDERR "Writing\n";
 	writeFromRam();
 

Modified: central-database/branches/alioth/webfrontend/browsetemplate.html
==============================================================================
--- central-database/branches/alioth/webfrontend/browsetemplate.html	(original)
+++ central-database/branches/alioth/webfrontend/browsetemplate.html	Sun Oct 30 13:46:00 2005
@@ -42,7 +42,7 @@
       <p><tmpl_var name="DESC"> (<tmpl_var name="COUNT"> packages):<br />
       <blockquote>
         <tmpl_loop name="SELTAGS">
-          <a href='<tmpl_var name="URL">'><tmpl_var name="DESC"></a> (<tmpl_var name="COUNT"> packages)<br />
+          <tmpl_var name="DESC"> (<tmpl_var name="COUNT"> packages) <a href='<tmpl_var name="URL">'>[remove]</a><br />
         </tmpl_loop>
 
         <select name="facet-<tmpl_var name="NAME">">

Modified: central-database/branches/alioth/webfrontend/index.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/index.cgi	(original)
+++ central-database/branches/alioth/webfrontend/index.cgi	Sun Oct 30 13:46:00 2005
@@ -119,6 +119,7 @@
 	elsif ($par eq 'words')
 	{
 		my $selwords = param($par);
+		msg "Found: %s->%s\n", $par, $selwords;
 		if ($selwords && $selwords =~ m/([a-z0-9\-:.,]+)/)
 		{
 			@sel_words = split(/\s+/, $1);
@@ -153,7 +154,7 @@
 	}
 }
 
-msg "Found %d packages\n", scalar(@pkgs);
+msg "Found %d packages: %s\n", scalar(@pkgs), join(', ', map { $_->{name} } @pkgs);
 
 #printf STDERR "Start: %d packages\n", scalar(@pkgs);
 



More information about the Debtags-commits mailing list