From fbc70034b3f5bd82d0cfe24a9a82a6d00237b46e Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 27 Oct 2021 11:50:57 +0200 Subject: Make the realisation fetching from binary caches async That way we can fetch several realisations from the same cache in parallel --- src/libstore/binary-cache-store.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index fb687db42..08dde0c54 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -441,16 +441,25 @@ void BinaryCacheStore::queryRealisationUncached(const DrvOutput & id, Callback> callback) noexcept { auto outputInfoFilePath = realisationsPrefix + "/" + id.to_string() + ".doi"; - auto rawOutputInfo = getFile(outputInfoFilePath); - if (rawOutputInfo) { - auto realisation = Realisation::fromJSON( - nlohmann::json::parse(*rawOutputInfo), outputInfoFilePath); - callback(std::make_shared(realisation)); - return; - } else { - callback(nullptr); - } + auto callbackPtr = std::make_shared(std::move(callback)); + + Callback> newCallback = { + [=](std::future> fut) { + try { + auto data = fut.get(); + if (!data) return (*callbackPtr)(nullptr); + + auto realisation = Realisation::fromJSON( + nlohmann::json::parse(*data), outputInfoFilePath); + return (*callbackPtr)(std::make_shared(realisation)); + } catch (...) { + callbackPtr->rethrow(); + } + } + }; + + getFile(outputInfoFilePath, std::move(newCallback)); } void BinaryCacheStore::registerDrvOutput(const Realisation& info) { -- cgit v1.2.3