From 28a98d152c071ec48b8bf510f87ac9710c56d7fb Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 28 Apr 2024 00:56:10 +0200 Subject: [PATCH] libstore: de-callback-ify Store::queryRealisation Change-Id: I8d74745c519518f163f51dfaa39063836f17599e --- src/libstore/store-api.cc | 81 +++++++++++++-------------------------- src/libstore/store-api.hh | 6 --- 2 files changed, 26 insertions(+), 61 deletions(-) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 7ebab3933..942e3f521 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -716,65 +716,36 @@ ref Store::queryPathInfo(const StorePath & storePath) return ref(info); } -void Store::queryRealisation(const DrvOutput & id, - Callback> callback) noexcept -{ - - try { - if (diskCache) { - auto [cacheOutcome, maybeCachedRealisation] - = diskCache->lookupRealisation(getUri(), id); - switch (cacheOutcome) { - case NarInfoDiskCache::oValid: - debug("Returning a cached realisation for %s", id.to_string()); - callback(maybeCachedRealisation); - return; - case NarInfoDiskCache::oInvalid: - debug( - "Returning a cached missing realisation for %s", - id.to_string()); - callback(nullptr); - return; - case NarInfoDiskCache::oUnknown: - break; - } - } - } catch (...) { - return callback.rethrow(); - } - - try { - auto info = queryRealisationUncached(id); - - if (diskCache) { - if (info) - diskCache->upsertRealisation(getUri(), *info); - else - diskCache->upsertAbsentRealisation(getUri(), id); - } - - callback(std::shared_ptr(info)); - - } catch (...) { - callback.rethrow(); - } -} - std::shared_ptr Store::queryRealisation(const DrvOutput & id) { - using RealPtr = std::shared_ptr; - std::promise promise; - queryRealisation(id, - {[&](std::future result) { - try { - promise.set_value(result.get()); - } catch (...) { - promise.set_exception(std::current_exception()); - } - }}); + if (diskCache) { + auto [cacheOutcome, maybeCachedRealisation] + = diskCache->lookupRealisation(getUri(), id); + switch (cacheOutcome) { + case NarInfoDiskCache::oValid: + debug("Returning a cached realisation for %s", id.to_string()); + return maybeCachedRealisation; + case NarInfoDiskCache::oInvalid: + debug( + "Returning a cached missing realisation for %s", + id.to_string()); + return nullptr; + case NarInfoDiskCache::oUnknown: + break; + } + } - return promise.get_future().get(); + auto info = queryRealisationUncached(id); + + if (diskCache) { + if (info) + diskCache->upsertRealisation(getUri(), *info); + else + diskCache->upsertAbsentRealisation(getUri(), id); + } + + return info; } void Store::substitutePaths(const StorePathSet & paths) diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 1aab3c8a3..47e644fed 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -371,12 +371,6 @@ public: */ std::shared_ptr queryRealisation(const DrvOutput &); - /** - * Asynchronous version of queryRealisation(). - */ - void queryRealisation(const DrvOutput &, - Callback> callback) noexcept; - /** * Check whether the given valid path info is sufficiently attested, by