mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
Test NAR info caching
This commit is contained in:
parent
05420e7883
commit
c642441beb
2 changed files with 15 additions and 5 deletions
|
@ -27,6 +27,8 @@ my $didExpiration = 0;
|
||||||
my $debug = ($ENV{"NIX_DEBUG_SUBST"} // "") eq 1;
|
my $debug = ($ENV{"NIX_DEBUG_SUBST"} // "") eq 1;
|
||||||
open(STDERR, ">>/dev/tty") if $debug;
|
open(STDERR, ">>/dev/tty") if $debug;
|
||||||
|
|
||||||
|
my $cacheFileURLs = ($ENV{"_NIX_CACHE_FILE_URLS"} // "") eq 1; # for testing
|
||||||
|
|
||||||
my ($dbh, $queryCache, $insertNAR, $queryNAR, $insertNARExistence, $queryNARExistence, $expireNARExistence);
|
my ($dbh, $queryCache, $insertNAR, $queryNAR, $insertNARExistence, $queryNARExistence, $expireNARExistence);
|
||||||
|
|
||||||
my $curlm = WWW::Curl::Multi->new;
|
my $curlm = WWW::Curl::Multi->new;
|
||||||
|
@ -267,6 +269,12 @@ sub getAvailableCaches {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub shouldCache {
|
||||||
|
my ($url) = @_;
|
||||||
|
return $cacheFileURLs || $url !~ /^file:/;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub processNARInfo {
|
sub processNARInfo {
|
||||||
my ($storePath, $cache, $request) = @_;
|
my ($storePath, $cache, $request) = @_;
|
||||||
|
|
||||||
|
@ -276,7 +284,7 @@ sub processNARInfo {
|
||||||
($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
|
($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
|
||||||
} else {
|
} else {
|
||||||
$insertNARExistence->execute($cache->{id}, basename($storePath), 0, time())
|
$insertNARExistence->execute($cache->{id}, basename($storePath), 0, time())
|
||||||
unless $request->{url} =~ /^file:/;
|
if shouldCache $request->{url};
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +297,7 @@ sub processNARInfo {
|
||||||
$cache->{id}, basename($storePath), $narInfo->{url}, $narInfo->{compression},
|
$cache->{id}, basename($storePath), $narInfo->{url}, $narInfo->{compression},
|
||||||
$narInfo->{fileHash}, $narInfo->{fileSize}, $narInfo->{narHash}, $narInfo->{narSize},
|
$narInfo->{fileHash}, $narInfo->{fileSize}, $narInfo->{narHash}, $narInfo->{narSize},
|
||||||
join(" ", @{$narInfo->{refs}}), $narInfo->{deriver}, $narInfo->{system}, time())
|
join(" ", @{$narInfo->{refs}}), $narInfo->{deriver}, $narInfo->{system}, time())
|
||||||
unless $request->{url} =~ /^file:/;
|
if shouldCache $request->{url};
|
||||||
|
|
||||||
return $narInfo;
|
return $narInfo;
|
||||||
}
|
}
|
||||||
|
@ -455,12 +463,12 @@ sub printSubstitutablePaths {
|
||||||
($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
|
($request->{result} != 0 ? "Curl error $request->{result}" : "HTTP status $request->{httpStatus}") . ")\n";
|
||||||
} else {
|
} else {
|
||||||
$insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 0, time())
|
$insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 0, time())
|
||||||
unless $request->{url} =~ /^file:/;
|
if shouldCache $request->{url};
|
||||||
}
|
}
|
||||||
push @left2, $request->{storePath};
|
push @left2, $request->{storePath};
|
||||||
} else {
|
} else {
|
||||||
$insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 1, time())
|
$insertNARExistence->execute($cache->{id}, basename($request->{storePath}), 1, time())
|
||||||
unless $request->{url} =~ /^file:/;
|
if shouldCache $request->{url};
|
||||||
print "$request->{storePath}\n";
|
print "$request->{storePath}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ clearManifests
|
||||||
|
|
||||||
# Create the binary cache.
|
# Create the binary cache.
|
||||||
cacheDir=$TEST_ROOT/binary-cache
|
cacheDir=$TEST_ROOT/binary-cache
|
||||||
rm -rf $cacheDir
|
rm -rf "$cacheDir"
|
||||||
|
|
||||||
outPath=$(nix-build dependencies.nix --no-out-link)
|
outPath=$(nix-build dependencies.nix --no-out-link)
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ nix-push --dest $cacheDir $outPath
|
||||||
clearStore
|
clearStore
|
||||||
rm -f $NIX_STATE_DIR/binary-cache*
|
rm -f $NIX_STATE_DIR/binary-cache*
|
||||||
|
|
||||||
|
export _NIX_CACHE_FILE_URLS=1
|
||||||
|
|
||||||
nix-env --option binary-caches "file://$cacheDir" -f dependencies.nix -qas \* | grep -- "---"
|
nix-env --option binary-caches "file://$cacheDir" -f dependencies.nix -qas \* | grep -- "---"
|
||||||
|
|
||||||
nix-store --option binary-caches "file://$cacheDir" -r $outPath
|
nix-store --option binary-caches "file://$cacheDir" -r $outPath
|
||||||
|
|
Loading…
Reference in a new issue