From 8bb85c6a94bdaf22dd379794c666fc040d6369a6 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 15 Sep 2025 11:29:14 +0100 Subject: [PATCH] Optimize Launchpad collection handling Various methods in `ubuntutools.lp.lpapicache` iterated over collections in a pessimal way: they fetched the collection and then fetched each individual entry in it, when the same information was already available in the collection response. Use more idiomatic launchpadlib code for this instead, which is also much faster. --- debian/changelog | 4 ++++ ubuntutools/lp/lpapicache.py | 15 ++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1d50796..35c5985 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,11 @@ ubuntu-dev-tools (0.207) UNRELEASED; urgency=medium + [ Dan Streetman ] * Fix pull-lp-source --upload-queue (LP: #2110061) + [ Colin Watson ] + * Optimize Launchpad collection handling. + -- Dan Streetman Tue, 06 May 2025 13:25:22 -0400 ubuntu-dev-tools (0.206) unstable; urgency=medium diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 22f5506..21ab051 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -290,9 +290,8 @@ class Distribution(BaseWrapper): Returns a list of all DistroSeries objects. """ if not self._have_all_series: - for series in Launchpad.load(self.series_collection_link).entries: - series_link = DistroSeries(series["self_link"]) - self._cache_series(series_link) + for series in self.series: + self._cache_series(DistroSeries(series)) self._have_all_series = True allseries = filter(lambda s: s.active, self._series.values()) @@ -1406,10 +1405,7 @@ class PersonTeam(BaseWrapper, metaclass=MetaPersonTeam): def getPPAs(self): if self._ppas is None: - ppas = [ - Archive(ppa["self_link"]) - for ppa in Launchpad.load(self._lpobject.ppas_collection_link).entries - ] + ppas = [Archive(ppa) for ppa in self._lpobject.ppas] self._ppas = {ppa.name: ppa for ppa in ppas} return self._ppas @@ -1434,10 +1430,7 @@ class Project(BaseWrapper): The list will be sorted by date_created, in descending order. """ if not self._series: - series = [ - ProjectSeries(s["self_link"]) - for s in Launchpad.load(self._lpobject.series_collection_link).entries - ] + series = [ProjectSeries(s) for s in self._lpobject.series] self._series = sorted(series, key=lambda s: s.date_created, reverse=True) return self._series.copy()