Make the realisation fetching from binary caches async
That way we can fetch several realisations from the same cache in parallel
This commit is contained in:
parent
96670ed216
commit
fbc70034b3
1 changed files with 18 additions and 9 deletions
|
@ -441,16 +441,25 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id,
|
||||||
Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
||||||
{
|
{
|
||||||
auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi";
|
auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi";
|
||||||
auto rawOutputInfo = getFile(outputInfoFilePath);
|
|
||||||
|
|
||||||
if (rawOutputInfo) {
|
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
||||||
|
|
||||||
|
Callback<std::shared_ptr<std::string>> newCallback = {
|
||||||
|
[=](std::future<std::shared_ptr<std::string>> fut) {
|
||||||
|
try {
|
||||||
|
auto data = fut.get();
|
||||||
|
if (!data) return (*callbackPtr)(nullptr);
|
||||||
|
|
||||||
auto realisation = Realisation::fromJSON(
|
auto realisation = Realisation::fromJSON(
|
||||||
nlohmann::json::parse(*rawOutputInfo), outputInfoFilePath);
|
nlohmann::json::parse(*data), outputInfoFilePath);
|
||||||
callback(std::make_shared<const Realisation>(realisation));
|
return (*callbackPtr)(std::make_shared<const Realisation>(realisation));
|
||||||
return;
|
} catch (...) {
|
||||||
} else {
|
callbackPtr->rethrow();
|
||||||
callback(nullptr);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getFile(outputInfoFilePath, std::move(newCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryCacheStore::registerDrvOutput(const Realisation& info) {
|
void BinaryCacheStore::registerDrvOutput(const Realisation& info) {
|
||||||
|
|
Loading…
Reference in a new issue