1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-09 10:31:02 +01:00

Merge pull request #14705 from NixOS/pathinfo-cache-string-to-store-path

libstore: Make Store::pathInfoCache use StorePath instead of std::string
This commit is contained in:
John Ericson 2025-12-04 03:33:51 +00:00 committed by GitHub
commit 676fb0fffc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 12 deletions

View file

@ -127,8 +127,7 @@ void BinaryCacheStore::writeNarInfo(ref<NarInfo> narInfo)
upsertFile(narInfoFile, narInfo->to_string(*this), "text/x-nix-narinfo"); upsertFile(narInfoFile, narInfo->to_string(*this), "text/x-nix-narinfo");
pathInfoCache->lock()->upsert( pathInfoCache->lock()->upsert(narInfo->path, PathInfoCacheValue{.value = std::shared_ptr<NarInfo>(narInfo)});
std::string(narInfo->path.to_string()), PathInfoCacheValue{.value = std::shared_ptr<NarInfo>(narInfo)});
if (diskCache) if (diskCache)
diskCache->upsertNarInfo( diskCache->upsertNarInfo(

View file

@ -310,7 +310,7 @@ protected:
// Note: this is a `ref` to avoid false sharing with immutable // Note: this is a `ref` to avoid false sharing with immutable
// bits of `Store`. // bits of `Store`.
ref<SharedSync<LRUCache<std::string, PathInfoCacheValue>>> pathInfoCache; ref<SharedSync<LRUCache<StorePath, PathInfoCacheValue>>> pathInfoCache;
std::shared_ptr<NarInfoDiskCache> diskCache; std::shared_ptr<NarInfoDiskCache> diskCache;

View file

@ -722,8 +722,7 @@ uint64_t LocalStore::addValidPath(State & state, const ValidPathInfo & info, boo
} }
} }
pathInfoCache->lock()->upsert( pathInfoCache->lock()->upsert(info.path, PathInfoCacheValue{.value = std::make_shared<const ValidPathInfo>(info)});
std::string(info.path.to_string()), PathInfoCacheValue{.value = std::make_shared<const ValidPathInfo>(info)});
return id; return id;
} }
@ -1021,7 +1020,7 @@ void LocalStore::invalidatePath(State & state, const StorePath & path)
/* Note that the foreign key constraints on the Refs table take /* Note that the foreign key constraints on the Refs table take
care of deleting the references entries for `path'. */ care of deleting the references entries for `path'. */
pathInfoCache->lock()->erase(std::string(path.to_string())); pathInfoCache->lock()->erase(path);
} }
const PublicKeys & LocalStore::getPublicKeys() const PublicKeys & LocalStore::getPublicKeys()

View file

@ -343,7 +343,7 @@ bool Store::PathInfoCacheValue::isKnownNow()
void Store::invalidatePathInfoCacheFor(const StorePath & path) void Store::invalidatePathInfoCacheFor(const StorePath & path)
{ {
pathInfoCache->lock()->erase(path.to_string()); pathInfoCache->lock()->erase(path);
} }
std::map<std::string, std::optional<StorePath>> Store::queryStaticPartialDerivationOutputMap(const StorePath & path) std::map<std::string, std::optional<StorePath>> Store::queryStaticPartialDerivationOutputMap(const StorePath & path)
@ -471,7 +471,7 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta
bool Store::isValidPath(const StorePath & storePath) bool Store::isValidPath(const StorePath & storePath)
{ {
auto res = pathInfoCache->lock()->get(storePath.to_string()); auto res = pathInfoCache->lock()->get(storePath);
if (res && res->isKnownNow()) { if (res && res->isKnownNow()) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
return res->didExist(); return res->didExist();
@ -483,7 +483,7 @@ bool Store::isValidPath(const StorePath & storePath)
if (res.first != NarInfoDiskCache::oUnknown) { if (res.first != NarInfoDiskCache::oUnknown) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
pathInfoCache->lock()->upsert( pathInfoCache->lock()->upsert(
storePath.to_string(), storePath,
res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{} res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{}
: PathInfoCacheValue{.value = res.second}); : PathInfoCacheValue{.value = res.second});
return res.first == NarInfoDiskCache::oValid; return res.first == NarInfoDiskCache::oValid;
@ -537,7 +537,7 @@ std::optional<std::shared_ptr<const ValidPathInfo>> Store::queryPathInfoFromClie
{ {
auto hashPart = std::string(storePath.hashPart()); auto hashPart = std::string(storePath.hashPart());
auto res = pathInfoCache->lock()->get(storePath.to_string()); auto res = pathInfoCache->lock()->get(storePath);
if (res && res->isKnownNow()) { if (res && res->isKnownNow()) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
if (res->didExist()) if (res->didExist())
@ -551,7 +551,7 @@ std::optional<std::shared_ptr<const ValidPathInfo>> Store::queryPathInfoFromClie
if (res.first != NarInfoDiskCache::oUnknown) { if (res.first != NarInfoDiskCache::oUnknown) {
stats.narInfoReadAverted++; stats.narInfoReadAverted++;
pathInfoCache->lock()->upsert( pathInfoCache->lock()->upsert(
storePath.to_string(), storePath,
res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{} res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{}
: PathInfoCacheValue{.value = res.second}); : PathInfoCacheValue{.value = res.second});
if (res.first == NarInfoDiskCache::oInvalid || !goodStorePath(storePath, res.second->path)) if (res.first == NarInfoDiskCache::oInvalid || !goodStorePath(storePath, res.second->path))
@ -591,7 +591,7 @@ void Store::queryPathInfo(const StorePath & storePath, Callback<ref<const ValidP
if (diskCache) if (diskCache)
diskCache->upsertNarInfo(config.getReference().render(/*FIXME withParams=*/false), hashPart, info); diskCache->upsertNarInfo(config.getReference().render(/*FIXME withParams=*/false), hashPart, info);
pathInfoCache->lock()->upsert(storePath.to_string(), PathInfoCacheValue{.value = info}); pathInfoCache->lock()->upsert(storePath, PathInfoCacheValue{.value = info});
if (!info || !goodStorePath(storePath, info->path)) { if (!info || !goodStorePath(storePath, info->path)) {
stats.narInfoMissing++; stats.narInfoMissing++;