* Speed up manifest generation.

This commit is contained in:
Eelco Dolstra 2009-02-26 16:57:05 +00:00
parent cf37152849
commit b1501bc1cd
2 changed files with 39 additions and 15 deletions

View file

@ -7,7 +7,8 @@ use File::Basename;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
isValidPath getHydraPath getHydraDBPath openHydraDB isValidPath queryPathInfo
getHydraPath getHydraDBPath openHydraDB
registerRoot getGCRootsDir registerRoot getGCRootsDir
getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease ); getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease );
@ -22,6 +23,39 @@ sub isValidPath {
} }
sub queryPathInfo {
my $path = shift;
# !!! like above, this breaks abstraction. What we really need is
# Perl bindings for libstore :-)
open FH, "</nix/var/nix/db/info/" . basename $path
or die "cannot open info file for $path";
my $hash;
my $deriver;
my @refs = ();
while (<FH>) {
if (/^Hash: (\S+)$/) {
$hash = $1;
}
elsif (/^Deriver: (\S+)$/) {
$deriver = $1;
}
elsif (/^References: (.*)$/) {
@refs = split / /, $1;
}
}
close FH;
die unless defined $hash;
return ($hash, $deriver, \@refs);
}
sub getHydraPath { sub getHydraPath {
my $dir = $ENV{"HYDRA_DATA"}; my $dir = $ENV{"HYDRA_DATA"};
die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir; die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir;

View file

@ -2,8 +2,7 @@ package Hydra::View::NixManifest;
use strict; use strict;
use base qw/Catalyst::View/; use base qw/Catalyst::View/;
use IO::Pipe; use Hydra::Helper::Nix;
use POSIX qw(dup2);
sub process { sub process {
@ -22,24 +21,15 @@ sub process {
"}\n"; "}\n";
foreach my $path (@paths) { foreach my $path (@paths) {
my @refs = split '\n', `nix-store --query --references $path`; my ($hash, $deriver, $refs) = queryPathInfo $path;
die "cannot query references of `$path': $?" if $? != 0;
my $hash = `nix-store --query --hash $path`
or die "cannot query hash of `$path': $?";
chomp $hash;
my $url = $c->stash->{narBase} . $path; my $url = $c->stash->{narBase} . $path;
my $deriver = `nix-store --query --deriver $path`
or die "cannot query deriver of `$path': $?";
chomp $deriver;
$manifest .= $manifest .=
"{\n" . "{\n" .
" StorePath: $path\n" . " StorePath: $path\n" .
(scalar @refs > 0 ? " References: @refs\n" : "") . (scalar @{$refs} > 0 ? " References: @{$refs}\n" : "") .
($deriver ne "unknown-deriver" ? " Deriver: $deriver\n" : "") . (defined $deriver ? " Deriver: $deriver\n" : "") .
" NarURL: $url\n" . " NarURL: $url\n" .
" NarHash: $hash\n" . " NarHash: $hash\n" .
"}\n"; "}\n";