mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 09:06:15 +02:00
Memoize queryReferrers()
This commit is contained in:
parent
17e6ebcc90
commit
304180d0de
1 changed files with 11 additions and 3 deletions
|
@ -617,6 +617,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::map<StorePath, StorePathSet> referrersCache;
|
||||||
|
|
||||||
/* Helper function that visits all paths reachable from `start`
|
/* Helper function that visits all paths reachable from `start`
|
||||||
via the referrers edges and optionally derivers and derivation
|
via the referrers edges and optionally derivers and derivation
|
||||||
output edges. If none of those paths are roots, then all
|
output edges. If none of those paths are roots, then all
|
||||||
|
@ -689,9 +691,14 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
if (isValidPath(*path)) {
|
if (isValidPath(*path)) {
|
||||||
|
|
||||||
/* Visit the referrers of this path. */
|
/* Visit the referrers of this path. */
|
||||||
StorePathSet referrers;
|
auto i = referrersCache.find(*path);
|
||||||
queryReferrers(*path, referrers);
|
if (i == referrersCache.end()) {
|
||||||
for (auto & p : referrers)
|
StorePathSet referrers;
|
||||||
|
queryReferrers(*path, referrers);
|
||||||
|
referrersCache.emplace(*path, std::move(referrers));
|
||||||
|
i = referrersCache.find(*path);
|
||||||
|
}
|
||||||
|
for (auto & p : i->second)
|
||||||
enqueue(p);
|
enqueue(p);
|
||||||
|
|
||||||
/* If keep-derivations is set and this is a
|
/* If keep-derivations is set and this is a
|
||||||
|
@ -718,6 +725,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
if (shouldDelete) {
|
if (shouldDelete) {
|
||||||
invalidatePathChecked(path);
|
invalidatePathChecked(path);
|
||||||
deleteFromStore(path.to_string());
|
deleteFromStore(path.to_string());
|
||||||
|
referrersCache.erase(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue