From b1501bc1cd5e426c3396066b328c24e22de222ff Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 26 Feb 2009 16:57:05 +0000 Subject: [PATCH] * Speed up manifest generation. --- src/Hydra/lib/Hydra/Helper/Nix.pm | 36 ++++++++++++++++++++++++- src/Hydra/lib/Hydra/View/NixManifest.pm | 18 +++---------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Hydra/lib/Hydra/Helper/Nix.pm b/src/Hydra/lib/Hydra/Helper/Nix.pm index c642c89e..6f65e2f5 100644 --- a/src/Hydra/lib/Hydra/Helper/Nix.pm +++ b/src/Hydra/lib/Hydra/Helper/Nix.pm @@ -7,7 +7,8 @@ use File::Basename; our @ISA = qw(Exporter); our @EXPORT = qw( - isValidPath getHydraPath getHydraDBPath openHydraDB + isValidPath queryPathInfo + getHydraPath getHydraDBPath openHydraDB registerRoot getGCRootsDir 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, ") { + 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 { my $dir = $ENV{"HYDRA_DATA"}; die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir; diff --git a/src/Hydra/lib/Hydra/View/NixManifest.pm b/src/Hydra/lib/Hydra/View/NixManifest.pm index 853decfb..cc4d1ab2 100644 --- a/src/Hydra/lib/Hydra/View/NixManifest.pm +++ b/src/Hydra/lib/Hydra/View/NixManifest.pm @@ -2,8 +2,7 @@ package Hydra::View::NixManifest; use strict; use base qw/Catalyst::View/; -use IO::Pipe; -use POSIX qw(dup2); +use Hydra::Helper::Nix; sub process { @@ -22,24 +21,15 @@ sub process { "}\n"; foreach my $path (@paths) { - my @refs = split '\n', `nix-store --query --references $path`; - die "cannot query references of `$path': $?" if $? != 0; + my ($hash, $deriver, $refs) = queryPathInfo $path; - my $hash = `nix-store --query --hash $path` - or die "cannot query hash of `$path': $?"; - chomp $hash; - my $url = $c->stash->{narBase} . $path; - my $deriver = `nix-store --query --deriver $path` - or die "cannot query deriver of `$path': $?"; - chomp $deriver; - $manifest .= "{\n" . " StorePath: $path\n" . - (scalar @refs > 0 ? " References: @refs\n" : "") . - ($deriver ne "unknown-deriver" ? " Deriver: $deriver\n" : "") . + (scalar @{$refs} > 0 ? " References: @{$refs}\n" : "") . + (defined $deriver ? " Deriver: $deriver\n" : "") . " NarURL: $url\n" . " NarHash: $hash\n" . "}\n";