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.
This commit is contained in:
Colin Watson 2025-09-15 11:29:14 +01:00
parent 7dd913fe16
commit 8bb85c6a94
2 changed files with 8 additions and 11 deletions

4
debian/changelog vendored
View File

@ -1,7 +1,11 @@
ubuntu-dev-tools (0.207) UNRELEASED; urgency=medium ubuntu-dev-tools (0.207) UNRELEASED; urgency=medium
[ Dan Streetman ]
* Fix pull-lp-source --upload-queue (LP: #2110061) * Fix pull-lp-source --upload-queue (LP: #2110061)
[ Colin Watson ]
* Optimize Launchpad collection handling.
-- Dan Streetman <ddstreet@ieee.org> Tue, 06 May 2025 13:25:22 -0400 -- Dan Streetman <ddstreet@ieee.org> Tue, 06 May 2025 13:25:22 -0400
ubuntu-dev-tools (0.206) unstable; urgency=medium ubuntu-dev-tools (0.206) unstable; urgency=medium

View File

@ -290,9 +290,8 @@ class Distribution(BaseWrapper):
Returns a list of all DistroSeries objects. Returns a list of all DistroSeries objects.
""" """
if not self._have_all_series: if not self._have_all_series:
for series in Launchpad.load(self.series_collection_link).entries: for series in self.series:
series_link = DistroSeries(series["self_link"]) self._cache_series(DistroSeries(series))
self._cache_series(series_link)
self._have_all_series = True self._have_all_series = True
allseries = filter(lambda s: s.active, self._series.values()) allseries = filter(lambda s: s.active, self._series.values())
@ -1406,10 +1405,7 @@ class PersonTeam(BaseWrapper, metaclass=MetaPersonTeam):
def getPPAs(self): def getPPAs(self):
if self._ppas is None: if self._ppas is None:
ppas = [ ppas = [Archive(ppa) for ppa in self._lpobject.ppas]
Archive(ppa["self_link"])
for ppa in Launchpad.load(self._lpobject.ppas_collection_link).entries
]
self._ppas = {ppa.name: ppa for ppa in ppas} self._ppas = {ppa.name: ppa for ppa in ppas}
return self._ppas return self._ppas
@ -1434,10 +1430,7 @@ class Project(BaseWrapper):
The list will be sorted by date_created, in descending order. The list will be sorted by date_created, in descending order.
""" """
if not self._series: if not self._series:
series = [ series = [ProjectSeries(s) for s in self._lpobject.series]
ProjectSeries(s["self_link"])
for s in Launchpad.load(self._lpobject.series_collection_link).entries
]
self._series = sorted(series, key=lambda s: s.date_created, reverse=True) self._series = sorted(series, key=lambda s: s.date_created, reverse=True)
return self._series.copy() return self._series.copy()