1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 20:16:03 +01:00

Store::addToStore bail out on no-op earlier in many cases

`BinaryCacheStore` and `LocalStore` already had this optimization. Now,
all the implementations do.
This commit is contained in:
John Ericson 2025-10-12 22:49:04 -04:00
parent f8095b793d
commit 456b917535
5 changed files with 28 additions and 2 deletions

View file

@ -296,8 +296,8 @@ void BinaryCacheStore::addToStore(
const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
if (!repair && isValidPath(info.path)) { if (!repair && isValidPath(info.path)) {
// FIXME: copyNAR -> null sink NullFileSystemObjectSink s;
narSource.drain(); parseDump(s, narSource);
return; return;
} }

View file

@ -160,6 +160,10 @@ struct DummyStoreImpl : DummyStore
void void
addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) override addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) override
{ {
if (!repair && isValidPath(info.path)) {
return;
}
if (config->readOnly) if (config->readOnly)
unsupported("addToStore"); unsupported("addToStore");

View file

@ -145,6 +145,12 @@ void LegacySSHStore::queryPathInfoUncached(
void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
if (!repair && isValidPath(info.path)) {
NullFileSystemObjectSink s;
parseDump(s, source);
return;
}
debug("adding path '%s' to remote host '%s'", printStorePath(info.path), config->authority.host); debug("adding path '%s' to remote host '%s'", printStorePath(info.path), config->authority.host);
auto conn(connections->get()); auto conn(connections->get());

View file

@ -424,6 +424,12 @@ StorePath RemoteStore::addToStoreFromDump(
void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
if (!repair && isValidPath(info.path)) {
NullFileSystemObjectSink s;
parseDump(s, source);
return;
}
auto conn(getConnection()); auto conn(getConnection());
conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path) conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path)

View file

@ -86,6 +86,12 @@ StorePath Store::followLinksToStorePath(std::string_view path) const
void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
if (!repair && isValidPath(info.path)) {
NullFileSystemObjectSink s;
parseDump(s, narSource);
return;
}
auto temp = make_ref<MemorySourceAccessor>(); auto temp = make_ref<MemorySourceAccessor>();
MemorySink tempSink{*temp}; MemorySink tempSink{*temp};
parseDump(tempSink, narSource); parseDump(tempSink, narSource);
@ -94,6 +100,10 @@ void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFla
void Store::addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) void Store::addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
if (!repair && isValidPath(info.path)) {
return;
}
auto sink = sourceToSink([&](Source & source) { addToStore(info, source, repair, checkSigs); }); auto sink = sourceToSink([&](Source & source) { addToStore(info, source, repair, checkSigs); });
dumpPath(path, *sink, FileSerialisationMethod::NixArchive); dumpPath(path, *sink, FileSerialisationMethod::NixArchive);
} }