@@ -659,7 +659,7 @@ void LocalStore::registerDrvOutput(const Realisation & info)
659
659
auto state (_state.lock ());
660
660
retrySQLite<void >([&]() {
661
661
state->stmts ->RegisterRealisedOutput .use ()
662
- (info.id .drvPath . to_string ())
662
+ (info.id .strHash ())
663
663
(info.id .outputName )
664
664
(printStorePath (info.outPath ))
665
665
.exec ();
@@ -879,17 +879,18 @@ StorePathSet LocalStore::queryValidDerivers(const StorePath & path)
879
879
880
880
// Try to resolve the derivation at path `original`, with a caching layer
881
881
// to make it more efficient
882
- std::optional<StorePath > cachedResolve (
883
- LocalStore & store,
884
- const StorePath & original)
882
+ std::optional<Derivation > cachedResolve (
883
+ LocalStore& store,
884
+ const StorePath& original)
885
885
{
886
+ // This is quite dirty and leaky, but will disappear once #4340 is merged
887
+ static Sync<std::map<StorePath, std::optional<Derivation>>> resolutionsCache;
886
888
{
887
- auto resolutions = drvPathResolutions.lock ();
888
- auto resolvedPathOptIter = resolutions->find (original);
889
- if (resolvedPathOptIter != resolutions->end ()) {
890
- auto & [_, resolvedPathOpt] = *resolvedPathOptIter;
891
- if (resolvedPathOpt)
892
- return resolvedPathOpt;
889
+ auto resolutions = resolutionsCache.lock ();
890
+ auto resolvedDrvIter = resolutions->find (original);
891
+ if (resolvedDrvIter != resolutions->end ()) {
892
+ auto & [_, resolvedDrv] = *resolvedDrvIter;
893
+ return *resolvedDrv;
893
894
}
894
895
}
895
896
@@ -898,12 +899,9 @@ std::optional<StorePath> cachedResolve(
898
899
auto attempt = drv.tryResolve (store);
899
900
if (!attempt)
900
901
return std::nullopt ;
901
- /* Just compute store path */
902
- auto pathResolved =
903
- writeDerivation (store, *std::move (attempt), NoRepair, true );
904
902
/* Store in memo table. */
905
- drvPathResolutions .lock ()->insert_or_assign (original, pathResolved );
906
- return pathResolved ;
903
+ resolutionsCache .lock ()->insert_or_assign (original, *attempt );
904
+ return *attempt ;
907
905
}
908
906
909
907
std::map<std::string, std::optional<StorePath>>
@@ -933,26 +931,24 @@ LocalStore::queryPartialDerivationOutputMap(const StorePath& path_)
933
931
934
932
auto drv = readDerivation (path);
935
933
936
- for (auto & output : drv.outputsAndOptPaths (*this )) {
937
- outputs.emplace (output.first , std::nullopt );
938
- }
939
-
940
934
auto resolvedDrv = cachedResolve (*this , path);
941
935
942
- if (!resolvedDrv)
936
+ if (!resolvedDrv) {
937
+ for (auto & [outputName, _] : drv.outputsAndOptPaths (*this )) {
938
+ if (!outputs.count (outputName))
939
+ outputs.emplace (outputName, std::nullopt );
940
+ }
943
941
return outputs;
942
+ }
944
943
945
- retrySQLite<void >([&]() {
946
- auto state (_state.lock ());
947
- path = *resolvedDrv;
948
- auto useQueryDerivationOutputs{
949
- state->stmts ->QueryAllRealisedOutputs .use ()(path.to_string ())};
950
-
951
- while (useQueryDerivationOutputs.next ())
952
- outputs.insert_or_assign (
953
- useQueryDerivationOutputs.getStr (0 ),
954
- parseStorePath (useQueryDerivationOutputs.getStr (1 )));
955
- });
944
+ auto resolvedDrvHashes = staticOutputHashes (*this , *resolvedDrv);
945
+ for (auto & [outputName, hash] : resolvedDrvHashes) {
946
+ auto realisation = queryRealisation (DrvOutput{hash, outputName});
947
+ if (realisation)
948
+ outputs.insert_or_assign (outputName, realisation->outPath );
949
+ else
950
+ outputs.insert_or_assign (outputName, std::nullopt );
951
+ }
956
952
957
953
return outputs;
958
954
}
@@ -1695,12 +1691,11 @@ std::optional<const Realisation> LocalStore::queryRealisation(
1695
1691
typedef std::optional<const Realisation> Ret;
1696
1692
return retrySQLite<Ret>([&]() -> Ret {
1697
1693
auto state (_state.lock ());
1698
- auto use (state->stmts ->QueryRealisedOutput .use ()(id.drvPath . to_string ())(
1694
+ auto use (state->stmts ->QueryRealisedOutput .use ()(id.strHash ())(
1699
1695
id.outputName ));
1700
1696
if (!use.next ())
1701
1697
return std::nullopt ;
1702
1698
auto outputPath = parseStorePath (use.getStr (0 ));
1703
- auto resolvedDrv = StorePath (use.getStr (1 ));
1704
1699
return Ret{
1705
1700
Realisation{.id = id, .outPath = outputPath}};
1706
1701
});
0 commit comments