From ad1997342725622da70be9af06bdaacdfa980051 Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Tue, 24 Oct 2023 18:29:10 +0400 Subject: [PATCH] repos: Cache for build report --- repos_cmp/repos.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/repos_cmp/repos.py b/repos_cmp/repos.py index 10e3a9c..11807a4 100644 --- a/repos_cmp/repos.py +++ b/repos_cmp/repos.py @@ -433,12 +433,21 @@ def _is_build_kind(kind): return kind in (_BUILDREQ, _BUILD_UNMET) +__BUILD_REPORT_CACHE = {} + + def build_report(from_repo, to_repo, source_name, ignore=(), prefer=()): """Build report for one source, by name Returns an iterable over tuples (kind, dep, provider). """ - LOG.debug("raw Build report for %s", source_name) + cache_key = (from_repo.name, to_repo.name, source_name, + frozenset(ignore), frozenset(prefer)) + cached_result = __BUILD_REPORT_CACHE.get(cache_key) + if cached_result is not None: + if cached_result.is_valid([from_repo, to_repo]): + return cached_result + LOG.debug("Building build report: %s", cache_key) # XXX: assumes from_repo is x86_64 assert from_repo.bits == 64 @@ -497,7 +506,9 @@ def build_report(from_repo, to_repo, source_name, ignore=(), prefer=()): LOG.info("Using preferred providers: %s", preferred) providers = preferred result.update((kind, dep, provider) for provider in providers) - return TripletReport([from_repo, to_repo], result) + the_report = TripletReport([from_repo, to_repo], result) + __BUILD_REPORT_CACHE[cache_key] = the_report + return the_report def _src_name(source):