1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 04:56:01 +01:00

fetchToStore(): Improve caching in dry-run mode

In dry-run mode, we don't need to require a valid path.
This commit is contained in:
Eelco Dolstra 2025-06-11 16:13:40 +02:00
parent ac6318c9c5
commit 2f5a545997
3 changed files with 8 additions and 6 deletions

View file

@ -122,7 +122,8 @@ struct CacheImpl : Cache
std::optional<ResultWithStorePath> lookupStorePath( std::optional<ResultWithStorePath> lookupStorePath(
Key key, Key key,
Store & store) override Store & store,
bool allowInvalid) override
{ {
key.second.insert_or_assign("store", store.storeDir); key.second.insert_or_assign("store", store.storeDir);
@ -135,7 +136,7 @@ struct CacheImpl : Cache
ResultWithStorePath res2(*res, StorePath(storePathS)); ResultWithStorePath res2(*res, StorePath(storePathS));
store.addTempRoot(res2.storePath); store.addTempRoot(res2.storePath);
if (!store.isValidPath(res2.storePath)) { if (!allowInvalid && !store.isValidPath(res2.storePath)) {
// FIXME: we could try to substitute 'storePath'. // FIXME: we could try to substitute 'storePath'.
debug("ignoring disappeared cache entry '%s:%s' -> '%s'", debug("ignoring disappeared cache entry '%s:%s' -> '%s'",
key.first, key.first,
@ -157,7 +158,7 @@ struct CacheImpl : Cache
Key key, Key key,
Store & store) override Store & store) override
{ {
auto res = lookupStorePath(std::move(key), store); auto res = lookupStorePath(std::move(key), store, false);
return res && !res->expired ? res : std::nullopt; return res && !res->expired ? res : std::nullopt;
} }
}; };

View file

@ -35,7 +35,7 @@ StorePath fetchToStore(
if (!filter && (fingerprint = path.accessor->getFingerprint(path.path))) { if (!filter && (fingerprint = path.accessor->getFingerprint(path.path))) {
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, path.path.abs()); cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, path.path.abs());
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store)) { if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store, mode == FetchMode::DryRun)) {
debug("store path cache hit for '%s'", path); debug("store path cache hit for '%s'", path);
return res->storePath; return res->storePath;
} }

View file

@ -76,11 +76,12 @@ struct Cache
/** /**
* Look up a store path in the cache. The returned store path will * Look up a store path in the cache. The returned store path will
* be valid, but it may be expired. * be valid (unless `allowInvalid` is true), but it may be expired.
*/ */
virtual std::optional<ResultWithStorePath> lookupStorePath( virtual std::optional<ResultWithStorePath> lookupStorePath(
Key key, Key key,
Store & store) = 0; Store & store,
bool allowInvalid = false) = 0;
/** /**
* Look up a store path in the cache. Return nothing if its TTL * Look up a store path in the cache. Return nothing if its TTL