aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-10-27 11:50:57 +0200
committerregnat <rg@regnat.ovh>2021-11-03 06:51:34 +0100
commitfbc70034b3f5bd82d0cfe24a9a82a6d00237b46e (patch)
treebf81f173110ddc893807d051f913d97e6a20b7e0 /src
parent96670ed2163d3d1a296c9b053833362ec8c06985 (diff)
Make the realisation fetching from binary caches async
That way we can fetch several realisations from the same cache in parallel
Diffstat (limited to 'src')
-rw-r--r--src/libstore/binary-cache-store.cc27
1 files changed, 18 insertions, 9 deletions
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<std::shared_ptr<const Realisation>> 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<const Realisation>(realisation));
- return;
- } else {
- callback(nullptr);
- }
+ 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(
+ nlohmann::json::parse(*data), outputInfoFilePath);
+ return (*callbackPtr)(std::make_shared<const Realisation>(realisation));
+ } catch (...) {
+ callbackPtr->rethrow();
+ }
+ }
+ };
+
+ getFile(outputInfoFilePath, std::move(newCallback));
}
void BinaryCacheStore::registerDrvOutput(const Realisation& info) {