From 4fa709ea86c8eefac05a848187fc7281edff8fa9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 9 Dec 2011 09:28:49 -0600 Subject: populate_signoffs: add an SVN log cache for duplicate lookups Signed-off-by: Dan McGee --- packages/management/commands/populate_signoffs.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/management/commands/populate_signoffs.py b/packages/management/commands/populate_signoffs.py index ce5ec734..42496e9d 100644 --- a/packages/management/commands/populate_signoffs.py +++ b/packages/management/commands/populate_signoffs.py @@ -44,6 +44,9 @@ def handle_noargs(self, **options): return add_signoff_comments() def svn_log(pkgbase, repo): + '''Retrieve the most recent SVN log entry for the given pkgbase and + repository. The configured setting SVN_BASE_URL is used along with the + svn_root for each repository to form the correct URL.''' path = '%s%s/%s/trunk/' % (settings.SVN_BASE_URL, repo.svn_root, pkgbase) cmd = ['svn', 'log', '--limit=1', '--xml', path] log_data = subprocess.check_output(cmd) @@ -59,6 +62,17 @@ def svn_log(pkgbase, repo): 'message': xml.findtext('logentry/msg'), } +def cached_svn_log(pkgbase, repo): + '''Retrieve the cached version of the SVN log if possible, else delegate to + svn_log() to do the work and cache the result.''' + key = (pkgbase, repo) + if key in cached_svn_log.cache: + return cached_svn_log.cache[key] + log = svn_log(pkgbase, repo) + cached_svn_log.cache[key] = log + return log +cached_svn_log.cache = {} + def create_specification(package, log, finder): trimmed_message = log['message'].strip() spec = SignoffSpecification(pkgbase=package.pkgbase, @@ -80,7 +94,7 @@ def add_signoff_comments(): continue logger.debug("getting SVN log for %s (%s)", group.pkgbase, group.repo) - log = svn_log(group.pkgbase, group.repo) + log = cached_svn_log(group.pkgbase, group.repo) logger.info("creating spec with SVN message for %s", group.pkgbase) spec = create_specification(group.packages[0], log, finder) spec.save() -- cgit v1.2.3-54-g00ecf