From c6d01458b4545500a964491c2602da3c3079bfc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 9 Aug 2022 22:11:08 +0200 Subject: Stored roots lookup --- src/storage.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/storage.cpp') diff --git a/src/storage.cpp b/src/storage.cpp index 5784309..c2d097e 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1029,6 +1029,34 @@ Generation Ref::generationLocked() const return gen; } +vector Ref::roots() const +{ + scoped_lock lock(p->storage->p->rootsCacheLock); + return rootsLocked(); +} + +vector Ref::rootsLocked() const +{ + auto it = p->storage->p->rootsCache.find(p->digest); + if (it != p->storage->p->rootsCache.end()) + return it->second; + + vector roots; + auto prev = previous(); + + if (prev.empty()) { + roots.push_back(p->digest); + } else { + for (const auto & p : previous()) + for (const auto & r : p.rootsLocked()) + roots.push_back(r); + + std::sort(roots.begin(), roots.end()); + roots.erase(std::unique(roots.begin(), roots.end()), roots.end()); + } + return roots; +} + template RecordT::Item::operator bool() const -- cgit v1.2.3