syncpackage: Cache the sync blocklist in-memory, so it's not fetched multiple times when syncing more than one package.

This commit is contained in:
Simon Quigley 2025-03-04 13:39:07 -06:00
parent 6c8a5d74bd
commit 2e550ceff2
2 changed files with 24 additions and 19 deletions

2
debian/changelog vendored
View File

@ -14,6 +14,8 @@ ubuntu-dev-tools (0.206) UNRELEASED; urgency=medium
variables (Closes: #725418). variables (Closes: #725418).
* mk-sbuild: default to using UTC for schroots (LP: #2097159). * mk-sbuild: default to using UTC for schroots (LP: #2097159).
* syncpackage: s/syncblacklist/syncblocklist/g * syncpackage: s/syncblacklist/syncblocklist/g
* syncpackage: Cache the sync blocklist in-memory, so it's not fetched
multiple times when syncing more than one package.
-- Simon Quigley <tsimonq2@debian.org> Tue, 04 Mar 2025 13:04:30 -0600 -- Simon Quigley <tsimonq2@debian.org> Tue, 04 Mar 2025 13:04:30 -0600

View File

@ -49,6 +49,7 @@ from ubuntutools.requestsync.mail import get_debian_srcpkg as requestsync_mail_g
from ubuntutools.version import Version from ubuntutools.version import Version
Logger = getLogger() Logger = getLogger()
cached_sync_blocklist = None
def remove_signature(dscname): def remove_signature(dscname):
@ -455,25 +456,27 @@ def is_blocklisted(query):
if diff.status == "Blacklisted always": if diff.status == "Blacklisted always":
blocklisted = "ALWAYS" blocklisted = "ALWAYS"
# Old blocklist: global cached_sync_blocklist
url = "https://ubuntu-archive-team.ubuntu.com/sync-blocklist.txt" if not cached_sync_blocklist:
with urllib.request.urlopen(url) as f: url = "https://ubuntu-archive-team.ubuntu.com/sync-blocklist.txt"
applicable_lines = [] with urllib.request.urlopen(url) as f:
for line in f: cached_sync_blocklist = f.read().decode("utf-8")
line = line.decode("utf-8")
if not line.strip(): applicable_lines = []
applicable_lines = [] for line in cached_sync_blocklist.splitlines():
continue if not line.strip():
applicable_lines.append(line) applicable_lines = []
try: continue
line = line[: line.index("#")] applicable_lines.append(line)
except ValueError: try:
pass line = line[:line.index("#")]
source = line.strip() except ValueError:
if source and fnmatch.fnmatch(query, source): pass
comments += ["From sync-blocklist.txt:"] + applicable_lines source = line.strip()
blocklisted = "ALWAYS" if source and fnmatch.fnmatch(query, source):
break comments += ["From sync-blocklist.txt:"] + applicable_lines
blocklisted = "ALWAYS"
break
return (blocklisted, comments) return (blocklisted, comments)