mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
refactor: Extract simply, awkwardly Store::queryPathInfoFromClientCache
This is useful for determining quickly which substituters to query. An alternative would be for users to invoke the narinfo cache db directly, so why do we need this change? - It is easier to use. I believe Nix itself should also use it. - This way, the narinfo cache db remains an implementation detail. - Callers get to use the in-memory cache as well.
This commit is contained in:
parent
01271f2996
commit
d0a284284b
2 changed files with 50 additions and 26 deletions
|
@ -685,20 +685,19 @@ static bool goodStorePath(const StorePath & expected, const StorePath & actual)
|
||||||
&& (expected.name() == Store::MissingName || expected.name() == actual.name());
|
&& (expected.name() == Store::MissingName || expected.name() == actual.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Store::queryPathInfoFromClientCache(const StorePath & storePath,
|
||||||
void Store::queryPathInfo(const StorePath & storePath,
|
Callback<ref<const ValidPathInfo>> & callback)
|
||||||
Callback<ref<const ValidPathInfo>> callback) noexcept
|
|
||||||
{
|
{
|
||||||
auto hashPart = std::string(storePath.hashPart());
|
auto hashPart = std::string(storePath.hashPart());
|
||||||
|
|
||||||
try {
|
|
||||||
{
|
{
|
||||||
auto res = state.lock()->pathInfoCache.get(std::string(storePath.to_string()));
|
auto res = state.lock()->pathInfoCache.get(std::string(storePath.to_string()));
|
||||||
if (res && res->isKnownNow()) {
|
if (res && res->isKnownNow()) {
|
||||||
stats.narInfoReadAverted++;
|
stats.narInfoReadAverted++;
|
||||||
if (!res->didExist())
|
if (!res->didExist())
|
||||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||||
return callback(ref<const ValidPathInfo>(res->value));
|
callback(ref<const ValidPathInfo>(res->value));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,10 +713,23 @@ void Store::queryPathInfo(const StorePath & storePath,
|
||||||
!goodStorePath(storePath, res.second->path))
|
!goodStorePath(storePath, res.second->path))
|
||||||
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
throw InvalidPath("path '%s' is not valid", printStorePath(storePath));
|
||||||
}
|
}
|
||||||
return callback(ref<const ValidPathInfo>(res.second));
|
callback(ref<const ValidPathInfo>(res.second));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Store::queryPathInfo(const StorePath & storePath,
|
||||||
|
Callback<ref<const ValidPathInfo>> callback) noexcept
|
||||||
|
{
|
||||||
|
auto hashPart = std::string(storePath.hashPart());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (queryPathInfoFromClientCache(storePath, callback))
|
||||||
|
return;
|
||||||
} catch (...) { return callback.rethrow(); }
|
} catch (...) { return callback.rethrow(); }
|
||||||
|
|
||||||
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
||||||
|
|
|
@ -282,6 +282,18 @@ public:
|
||||||
void queryPathInfo(const StorePath & path,
|
void queryPathInfo(const StorePath & path,
|
||||||
Callback<ref<const ValidPathInfo>> callback) noexcept;
|
Callback<ref<const ValidPathInfo>> callback) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTE: this is not the final interface - to be modified in next commit.
|
||||||
|
*
|
||||||
|
* Asynchronous version that only queries the local narinfo cache and not
|
||||||
|
* the actual store.
|
||||||
|
*
|
||||||
|
* @return true if the path was known and the callback invoked
|
||||||
|
* @return false if the path was not known and the callback not invoked
|
||||||
|
* @throw InvalidPathError if the path is known to be invalid
|
||||||
|
*/
|
||||||
|
bool queryPathInfoFromClientCache(const StorePath & path, Callback<ref<const ValidPathInfo>> & callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the information about a realisation.
|
* Query the information about a realisation.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue