launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29560
[Merge] ~cjwatson/launchpad:stormify-distribution-caches into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:stormify-distribution-caches into launchpad:master.
Commit message:
Convert distribution/distroseries caches to Storm
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/435995
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-distribution-caches into launchpad:master.
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index af6ce95..80433cc 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -1581,7 +1581,7 @@ class Distribution(
conditions = [
DistributionSourcePackageCache.distribution == self,
Or(
- DistributionSourcePackageCache.archiveID.is_in(
+ DistributionSourcePackageCache.archive_id.is_in(
self.all_distro_archive_ids
),
DistributionSourcePackageCache.archive == None,
@@ -1613,7 +1613,7 @@ class Distribution(
Join(
SourcePackagePublishingHistory,
SourcePackagePublishingHistory.sourcepackagenameID
- == DistributionSourcePackageCache.sourcepackagenameID,
+ == DistributionSourcePackageCache.sourcepackagename_id,
)
)
conditions.extend(
@@ -1668,7 +1668,7 @@ class Distribution(
find_spec = (
DistributionSourcePackageCache.distribution == self,
- DistributionSourcePackageCache.archiveID.is_in(
+ DistributionSourcePackageCache.archive_id.is_in(
self.all_distro_archive_ids
),
)
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index 68f102f..0c7cbd8 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -1290,7 +1290,7 @@ class DistroSeries(
.find(
find_spec,
DistroSeriesPackageCache.distroseries == self,
- DistroSeriesPackageCache.archiveID.is_in(
+ DistroSeriesPackageCache.archive_id.is_in(
self.distribution.all_distro_archive_ids
),
Or(
diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py
index df45ef0..59a48a8 100644
--- a/lib/lp/registry/vocabularies.py
+++ b/lib/lp/registry/vocabularies.py
@@ -2098,7 +2098,7 @@ class SourcePackageNameVocabulary(NamedStormHugeVocabulary):
_clauses = [
SourcePackageName.id.is_in(
Select(
- DistributionSourcePackageCache.sourcepackagenameID,
+ DistributionSourcePackageCache.sourcepackagename_id,
# No current users of this vocabulary can easily provide a
# distribution context, since the distribution and source
# package name are typically selected together, so the best
@@ -2111,7 +2111,7 @@ class SourcePackageNameVocabulary(NamedStormHugeVocabulary):
tables=LeftJoin(
DistributionSourcePackageCache,
Archive,
- DistributionSourcePackageCache.archiveID == Archive.id,
+ DistributionSourcePackageCache.archive_id == Archive.id,
),
)
),
@@ -2214,7 +2214,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase):
def _cache_location_clauses(self):
return [
Or(
- DistributionSourcePackageCache.archiveID.is_in(
+ DistributionSourcePackageCache.archive_id.is_in(
self.distribution.all_distro_archive_ids
),
DistributionSourcePackageCache.archive == None,
@@ -2260,7 +2260,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase):
empty = (
IStore(DistributionSourcePackageCache)
.find(
- DistributionSourcePackageCache.sourcepackagenameID,
+ DistributionSourcePackageCache.sourcepackagename_id,
*self._cache_location_clauses,
)
.is_empty()
@@ -2302,7 +2302,7 @@ class DistributionSourcePackageVocabulary(FilteredVocabularyBase):
Select(
(
DSPC.name,
- DSPC.sourcepackagenameID,
+ DSPC.sourcepackagename_id,
DSPC.binpkgnames,
),
where=And(
diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
index 3ec4d53..770c5d2 100644
--- a/lib/lp/scripts/garbo.py
+++ b/lib/lp/scripts/garbo.py
@@ -544,16 +544,20 @@ class PopulateDistributionSourcePackageCache(TunableLoop):
DistributionSourcePackageCache,
In(
Row(
- DistributionSourcePackageCache.archiveID,
- DistributionSourcePackageCache.distributionID,
- DistributionSourcePackageCache.sourcepackagenameID,
+ DistributionSourcePackageCache.archive_id,
+ DistributionSourcePackageCache.distribution_id,
+ DistributionSourcePackageCache.sourcepackagename_id,
),
[Row(cache_key) for cache_key in cache_filter_data],
),
)
for dspc in rows:
existing_records.add(
- (dspc.archiveID, dspc.distributionID, dspc.sourcepackagenameID)
+ (
+ dspc.archive_id,
+ dspc.distribution_id,
+ dspc.sourcepackagename_id,
+ )
)
# Bulk-create missing cache rows.
@@ -566,9 +570,9 @@ class PopulateDistributionSourcePackageCache(TunableLoop):
if inserts:
create(
(
- DistributionSourcePackageCache.archiveID,
- DistributionSourcePackageCache.distributionID,
- DistributionSourcePackageCache.sourcepackagenameID,
+ DistributionSourcePackageCache.archive_id,
+ DistributionSourcePackageCache.distribution_id,
+ DistributionSourcePackageCache.sourcepackagename_id,
DistributionSourcePackageCache.name,
),
inserts,
diff --git a/lib/lp/soyuz/doc/package-cache.rst b/lib/lp/soyuz/doc/package-cache.rst
index 27b7c44..d74ac9a 100644
--- a/lib/lp/soyuz/doc/package-cache.rst
+++ b/lib/lp/soyuz/doc/package-cache.rst
@@ -20,6 +20,7 @@ DistributionSourcePackageCache table, including:
generated by this source.
>>> from lp.registry.interfaces.distribution import IDistributionSet
+ >>> from lp.services.database.interfaces import IStore
>>> from lp.soyuz.model.distributionsourcepackagecache import (
... DistributionSourcePackageCache,
... )
@@ -112,8 +113,15 @@ cache when it's updated.
>>> ubuntu.searchSourcePackages("foobar").count()
1
- >>> foobar_cache = DistributionSourcePackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distribution=ubuntu, name="foobar"
+ >>> foobar_cache = (
+ ... IStore(DistributionSourcePackageCache)
+ ... .find(
+ ... DistributionSourcePackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distribution=ubuntu,
+ ... name="foobar",
+ ... )
+ ... .one()
... )
>>> foobar_cache is not None
@@ -136,8 +144,15 @@ Let's use a fake logger object:
>>> ubuntu.searchSourcePackages("foobar").count()
0
- >>> foobar_cache = DistributionSourcePackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distribution=ubuntu, name="foobar"
+ >>> foobar_cache = (
+ ... IStore(DistributionSourcePackageCache)
+ ... .find(
+ ... DistributionSourcePackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distribution=ubuntu,
+ ... name="foobar",
+ ... )
+ ... .one()
... )
>>> foobar_cache is None
@@ -155,8 +170,15 @@ cache when it's updated the next time.
>>> ubuntu.searchSourcePackages("cdrkit").count()
0
- >>> cdrkit_cache = DistributionSourcePackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distribution=ubuntu, name="cdrkit"
+ >>> cdrkit_cache = (
+ ... IStore(DistributionSourcePackageCache)
+ ... .find(
+ ... DistributionSourcePackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distribution=ubuntu,
+ ... name="cdrkit",
+ ... )
+ ... .one()
... )
>>> cdrkit_cache is None
@@ -185,8 +207,15 @@ reached via searches:
>>> ubuntu.searchSourcePackages("cdrkit").count()
1
- >>> cdrkit_cache = DistributionSourcePackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distribution=ubuntu, name="cdrkit"
+ >>> cdrkit_cache = (
+ ... IStore(DistributionSourcePackageCache)
+ ... .find(
+ ... DistributionSourcePackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distribution=ubuntu,
+ ... name="cdrkit",
+ ... )
+ ... .one()
... )
>>> cdrkit_cache is not None
@@ -208,8 +237,15 @@ cache when it's updated.
>>> warty.searchPackages("foobar").count()
1
- >>> foobar_bin_cache = DistroSeriesPackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distroseries=warty, name="foobar"
+ >>> foobar_bin_cache = (
+ ... IStore(DistroSeriesPackageCache)
+ ... .find(
+ ... DistroSeriesPackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distroseries=warty,
+ ... name="foobar",
+ ... )
+ ... .one()
... )
>>> foobar_bin_cache is not None
@@ -228,8 +264,15 @@ offers a method for removing obsolete records in cache:
>>> warty.searchPackages("foobar").count()
0
- >>> foobar_bin_cache = DistroSeriesPackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distroseries=warty, name="foobar"
+ >>> foobar_bin_cache = (
+ ... IStore(DistroSeriesPackageCache)
+ ... .find(
+ ... DistroSeriesPackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distroseries=warty,
+ ... name="foobar",
+ ... )
+ ... .one()
... )
>>> foobar_bin_cache is None
@@ -246,8 +289,15 @@ cache will be added to it.
>>> warty.searchPackages("cdrkit").count()
0
- >>> cdrkit_bin_cache = DistroSeriesPackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distroseries=warty, name="cdrkit"
+ >>> cdrkit_bin_cache = (
+ ... IStore(DistroSeriesPackageCache)
+ ... .find(
+ ... DistroSeriesPackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distroseries=warty,
+ ... name="cdrkit",
+ ... )
+ ... .one()
... )
>>> cdrkit_bin_cache is None
@@ -281,8 +331,15 @@ reached via searches:
>>> warty.searchPackages("cdrkit").count()
1
- >>> cdrkit_bin_cache = DistroSeriesPackageCache.selectOneBy(
- ... archive=ubuntu.main_archive, distroseries=warty, name="cdrkit"
+ >>> cdrkit_bin_cache = (
+ ... IStore(DistroSeriesPackageCache)
+ ... .find(
+ ... DistroSeriesPackageCache,
+ ... archive=ubuntu.main_archive,
+ ... distroseries=warty,
+ ... name="cdrkit",
+ ... )
+ ... .one()
... )
>>> cdrkit_bin_cache is not None
@@ -400,19 +457,17 @@ the following tasks:
We remove all caches related to Celso's PPA.
- >>> celso_source_caches = DistributionSourcePackageCache.selectBy(
- ... archive=cprov.archive
+ >>> celso_source_caches = IStore(DistributionSourcePackageCache).find(
+ ... DistributionSourcePackageCache, archive=cprov.archive
... )
- >>> celso_binary_caches = DistroSeriesPackageCache.selectBy(
- ... archive=cprov.archive
+ >>> celso_binary_caches = IStore(DistroSeriesPackageCache).find(
+ ... DistroSeriesPackageCache, archive=cprov.archive
... )
- >>> from zope.security.proxy import removeSecurityProxy
>>> def purge_caches(caches):
... for cache in caches:
- ... naked_cache = removeSecurityProxy(cache)
- ... naked_cache.destroySelf()
+ ... IStore(cache).remove(cache)
...
>>> purge_caches(celso_source_caches)
@@ -471,7 +526,7 @@ unique and lowercase words free of any punctuation.
Let's remove the unclean cache and update Celso's PPA cache, so
everything will be back to normal.
- >>> removeSecurityProxy(unclean_cache).destroySelf()
+ >>> IStore(unclean_cache).remove(unclean_cache)
>>> cprov.archive.updateArchiveCache()
@@ -501,12 +556,17 @@ with a null archive column.
Updating the cache adds missing entries to the cache.
- >>> branch_cache = DistributionSourcePackageCache.selectOneBy(
- ... archive=None,
- ... distribution=ubuntu,
- ... name=branch.sourcepackagename.name,
+ >>> branch_cache = (
+ ... IStore(DistributionSourcePackageCache)
+ ... .find(
+ ... DistributionSourcePackageCache,
+ ... archive=None,
+ ... distribution=ubuntu,
+ ... name=branch.sourcepackagename.name,
+ ... )
+ ... .one()
... )
- >>> removeSecurityProxy(branch_cache).destroySelf()
+ >>> IStore(branch_cache).remove(branch_cache)
>>> ubuntu.searchSourcePackages(branch.sourcepackagename.name).count()
0
>>> updates = DistributionSourcePackageCache.updateAll(
@@ -780,10 +840,12 @@ First, we rebuild and examinate the caches for Celso's PPA.
... archive.updateArchiveCache()
...
>>> def print_caches(archive):
- ... source_caches = DistributionSourcePackageCache.selectBy(
- ... archive=archive
+ ... source_caches = IStore(DistributionSourcePackageCache).find(
+ ... DistributionSourcePackageCache, archive=archive
+ ... )
+ ... binary_caches = IStore(DistroSeriesPackageCache).find(
+ ... DistroSeriesPackageCache, archive=archive
... )
- ... binary_caches = DistroSeriesPackageCache.selectBy(archive=archive)
... print(
... "%d sources cached [%d]"
... % (archive.sources_cached, source_caches.count())
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index ec04a41..c04e77f 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -1205,6 +1205,9 @@ class Archive(SQLBase):
def updateArchiveCache(self):
"""See `IArchive`."""
+ # Circular imports.
+ from lp.registry.model.distribution import Distribution
+ from lp.registry.model.distroseries import DistroSeries
from lp.soyuz.model.distributionsourcepackagecache import (
DistributionSourcePackageCache,
)
@@ -1235,20 +1238,24 @@ class Archive(SQLBase):
# Cache source package name and its binaries information, binary
# names and summaries.
- sources_cached = DistributionSourcePackageCache.select(
- "archive = %s" % sqlvalues(self), prejoins=["distribution"]
+ sources_cached = IStore(DistributionSourcePackageCache).find(
+ (DistributionSourcePackageCache, Distribution),
+ DistributionSourcePackageCache.archive == self,
+ DistributionSourcePackageCache.distribution_id == Distribution.id,
)
- for cache in sources_cached:
+ for cache, _ in sources_cached:
add_cache_content(cache.distribution.name)
add_cache_content(cache.name)
add_cache_content(cache.binpkgnames)
add_cache_content(cache.binpkgsummaries)
# Cache distroseries names with binaries.
- binaries_cached = DistroSeriesPackageCache.select(
- "archive = %s" % sqlvalues(self), prejoins=["distroseries"]
+ binaries_cached = IStore(DistroSeriesPackageCache).find(
+ (DistroSeriesPackageCache, DistroSeries),
+ DistroSeriesPackageCache.archive == self,
+ DistroSeriesPackageCache.distroseries_id == DistroSeries.id,
)
- for cache in binaries_cached:
+ for cache, _ in binaries_cached:
add_cache_content(cache.distroseries.name)
# Collapse all relevant terms in 'package_description_cache' and
diff --git a/lib/lp/soyuz/model/distributionsourcepackagecache.py b/lib/lp/soyuz/model/distributionsourcepackagecache.py
index e4a3837..31ee732 100644
--- a/lib/lp/soyuz/model/distributionsourcepackagecache.py
+++ b/lib/lp/soyuz/model/distributionsourcepackagecache.py
@@ -8,6 +8,7 @@ __all__ = [
from collections import defaultdict
from operator import attrgetter, itemgetter
+from storm.locals import Int, Reference, Unicode
from zope.interface import implementer
from lp.code.model.seriessourcepackagebranch import SeriesSourcePackageBranch
@@ -16,8 +17,7 @@ from lp.registry.model.sourcepackagename import SourcePackageName
from lp.services.database import bulk
from lp.services.database.decoratedresultset import DecoratedResultSet
from lp.services.database.interfaces import IStore
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey, StringCol
+from lp.services.database.stormbase import StormBase
from lp.soyuz.interfaces.distributionsourcepackagecache import (
IDistributionSourcePackageCache,
)
@@ -32,24 +32,39 @@ _DEFAULT = object()
@implementer(IDistributionSourcePackageCache)
-class DistributionSourcePackageCache(SQLBase):
- _table = "DistributionSourcePackageCache"
-
- archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=False)
- distribution = ForeignKey(
- dbName="distribution", foreignKey="Distribution", notNull=True
- )
- sourcepackagename = ForeignKey(
- dbName="sourcepackagename",
- foreignKey="SourcePackageName",
- notNull=True,
- )
-
- name = StringCol(notNull=False, default=None)
- binpkgnames = StringCol(notNull=False, default=None)
- binpkgsummaries = StringCol(notNull=False, default=None)
- binpkgdescriptions = StringCol(notNull=False, default=None)
- changelog = StringCol(notNull=False, default=None)
+class DistributionSourcePackageCache(StormBase):
+ __storm_table__ = "DistributionSourcePackageCache"
+
+ id = Int(primary=True)
+ archive_id = Int(name="archive", allow_none=True)
+ archive = Reference(archive_id, "Archive.id")
+ distribution_id = Int(name="distribution", allow_none=False)
+ distribution = Reference(distribution_id, "Distribution.id")
+ sourcepackagename_id = Int(name="sourcepackagename", allow_none=False)
+ sourcepackagename = Reference(sourcepackagename_id, "SourcePackageName.id")
+
+ name = Unicode(allow_none=True, default=None)
+ binpkgnames = Unicode(allow_none=True, default=None)
+ binpkgsummaries = Unicode(allow_none=True, default=None)
+ binpkgdescriptions = Unicode(allow_none=True, default=None)
+ changelog = Unicode(allow_none=True, default=None)
+
+ def __init__(
+ self,
+ archive,
+ distribution,
+ sourcepackagename,
+ name=None,
+ binpkgnames=None,
+ binpkgsummaries=None,
+ ):
+ super().__init__()
+ self.archive = archive
+ self.distribution = distribution
+ self.sourcepackagename = sourcepackagename
+ self.name = name
+ self.binpkgnames = binpkgnames
+ self.binpkgsummaries = binpkgsummaries
@property
def distributionsourcepackage(self):
@@ -89,7 +104,7 @@ class DistributionSourcePackageCache(SQLBase):
If 'archive' is not given it will return all caches stored for the
distribution main archives (PRIMARY and PARTNER).
"""
- archive_column = DistributionSourcePackageCache.archiveID
+ archive_column = DistributionSourcePackageCache.archive_id
if archive is _DEFAULT:
archive_clause = archive_column.is_in(
distro.all_distro_archive_ids
@@ -106,7 +121,7 @@ class DistributionSourcePackageCache(SQLBase):
DistributionSourcePackageCache.distribution == distro,
archive_clause,
SourcePackageName.id
- == DistributionSourcePackageCache.sourcepackagenameID,
+ == DistributionSourcePackageCache.sourcepackagename_id,
)
.order_by(DistributionSourcePackageCache.name)
)
@@ -137,7 +152,7 @@ class DistributionSourcePackageCache(SQLBase):
"Removing source cache for '%s' (%s)"
% (cache.name, cache.id)
)
- cache.destroySelf()
+ IStore(cache).remove(cache)
@classmethod
def update(
@@ -180,7 +195,7 @@ class DistributionSourcePackageCache(SQLBase):
cls,
cls.distribution == distro,
cls.archive == archive,
- cls.sourcepackagenameID.is_in(
+ cls.sourcepackagename_id.is_in(
[spn.id for spn in sourcepackagenames]
),
)
@@ -285,7 +300,7 @@ class DistributionSourcePackageCache(SQLBase):
cls,
cls.distribution == distro,
cls.archive == None,
- cls.sourcepackagenameID.is_in(
+ cls.sourcepackagename_id.is_in(
[spn.id for spn in sourcepackagenames]
),
)
diff --git a/lib/lp/soyuz/model/distributionsourcepackagerelease.py b/lib/lp/soyuz/model/distributionsourcepackagerelease.py
index 1f7e663..9002ce6 100644
--- a/lib/lp/soyuz/model/distributionsourcepackagerelease.py
+++ b/lib/lp/soyuz/model/distributionsourcepackagerelease.py
@@ -189,7 +189,7 @@ class DistributionSourcePackageRelease:
DistroSeriesPackageCache,
And(
DistroSeriesPackageCache.distroseries == DistroSeries.id,
- DistroSeriesPackageCache.archiveID.is_in(archive_ids),
+ DistroSeriesPackageCache.archive_id.is_in(archive_ids),
DistroSeriesPackageCache.binarypackagename
== BinaryPackageName.id,
),
diff --git a/lib/lp/soyuz/model/distroarchseriesbinarypackage.py b/lib/lp/soyuz/model/distroarchseriesbinarypackage.py
index 035c96a..d85b423 100644
--- a/lib/lp/soyuz/model/distroarchseriesbinarypackage.py
+++ b/lib/lp/soyuz/model/distroarchseriesbinarypackage.py
@@ -13,7 +13,6 @@ from zope.interface import implementer
from lp.app.errors import NotFoundError
from lp.services.database.interfaces import IStore
-from lp.services.database.sqlbase import sqlvalues
from lp.services.propertycache import cachedproperty
from lp.soyuz.enums import PackagePublishingStatus
from lp.soyuz.interfaces.distroarchseriesbinarypackage import (
@@ -78,18 +77,20 @@ class DistroArchSeriesBinaryPackage:
DistroSeriesPackageCache,
)
- query = """
- distroseries = %s AND
- archive IN %s AND
- binarypackagename = %s
- """ % sqlvalues(
- self.distroseries,
- self.distribution.all_distro_archive_ids,
- self.binarypackagename,
+ return (
+ IStore(DistroSeriesPackageCache)
+ .find(
+ DistroSeriesPackageCache,
+ DistroSeriesPackageCache.distroseries == self.distroseries,
+ DistroSeriesPackageCache.archive_id.is_in(
+ self.distribution.all_distro_archive_ids
+ ),
+ DistroSeriesPackageCache.binarypackagename
+ == self.binarypackagename,
+ )
+ .one()
)
- return DistroSeriesPackageCache.selectOne(query)
-
@property
def summary(self):
"""See IDistroArchSeriesBinaryPackage."""
diff --git a/lib/lp/soyuz/model/distroseriesbinarypackage.py b/lib/lp/soyuz/model/distroseriesbinarypackage.py
index 8946c36..3e3f4c5 100644
--- a/lib/lp/soyuz/model/distroseriesbinarypackage.py
+++ b/lib/lp/soyuz/model/distroseriesbinarypackage.py
@@ -68,7 +68,7 @@ class DistroSeriesBinaryPackage:
result = store.find(
DistroSeriesPackageCache,
DistroSeriesPackageCache.distroseries == self.distroseries,
- DistroSeriesPackageCache.archiveID.is_in(archive_ids),
+ DistroSeriesPackageCache.archive_id.is_in(archive_ids),
(
DistroSeriesPackageCache.binarypackagename
== self.binarypackagename
diff --git a/lib/lp/soyuz/model/distroseriespackagecache.py b/lib/lp/soyuz/model/distroseriespackagecache.py
index 2bb7d52..bc7a9bc 100644
--- a/lib/lp/soyuz/model/distroseriespackagecache.py
+++ b/lib/lp/soyuz/model/distroseriespackagecache.py
@@ -9,12 +9,12 @@ from collections import defaultdict
from operator import attrgetter
from storm.expr import Desc, Max, Select
+from storm.locals import Int, Reference, Unicode
from zope.interface import implementer
from lp.services.database import bulk
from lp.services.database.interfaces import IStore
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey, StringCol
+from lp.services.database.stormbase import StormBase
from lp.soyuz.interfaces.distroseriespackagecache import (
IDistroSeriesPackageCache,
)
@@ -26,24 +26,37 @@ from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
@implementer(IDistroSeriesPackageCache)
-class DistroSeriesPackageCache(SQLBase):
- _table = "DistroSeriesPackageCache"
-
- archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=True)
- distroseries = ForeignKey(
- dbName="distroseries", foreignKey="DistroSeries", notNull=True
- )
- binarypackagename = ForeignKey(
- dbName="binarypackagename",
- foreignKey="BinaryPackageName",
- notNull=True,
- )
-
- name = StringCol(notNull=False, default=None)
- summary = StringCol(notNull=False, default=None)
- description = StringCol(notNull=False, default=None)
- summaries = StringCol(notNull=False, default=None)
- descriptions = StringCol(notNull=False, default=None)
+class DistroSeriesPackageCache(StormBase):
+ __storm_table__ = "DistroSeriesPackageCache"
+
+ id = Int(primary=True)
+ archive_id = Int(name="archive", allow_none=False)
+ archive = Reference(archive_id, "Archive.id")
+ distroseries_id = Int(name="distroseries", allow_none=False)
+ distroseries = Reference(distroseries_id, "DistroSeries.id")
+ binarypackagename_id = Int(name="binarypackagename", allow_none=False)
+ binarypackagename = Reference(binarypackagename_id, "BinaryPackageName.id")
+
+ name = Unicode(allow_none=True, default=None)
+ summary = Unicode(allow_none=True, default=None)
+ description = Unicode(allow_none=True, default=None)
+ summaries = Unicode(allow_none=True, default=None)
+ descriptions = Unicode(allow_none=True, default=None)
+
+ def __init__(
+ self,
+ archive,
+ distroseries,
+ binarypackagename,
+ summary=None,
+ description=None,
+ ):
+ super().__init__()
+ self.archive = archive
+ self.distroseries = distroseries
+ self.binarypackagename = binarypackagename
+ self.summary = summary
+ self.description = description
@classmethod
def findCurrentBinaryPackageNames(cls, archive, distroseries):
@@ -84,7 +97,7 @@ class DistroSeriesPackageCache(SQLBase):
.find(
cls,
cls.distroseries == distroseries,
- cls.archiveID.is_in(archives),
+ cls.archive_id.is_in(archives),
)
.order_by(cls.name)
)
@@ -116,7 +129,7 @@ class DistroSeriesPackageCache(SQLBase):
"Removing binary cache for '%s' (%s)"
% (cache.name, cache.id)
)
- cache.destroySelf()
+ IStore(cache).remove(cache)
@classmethod
def _update(cls, distroseries, binarypackagenames, archive, log):
@@ -177,7 +190,7 @@ class DistroSeriesPackageCache(SQLBase):
cls,
cls.distroseries == distroseries,
cls.archive == archive,
- cls.binarypackagenameID.is_in(
+ cls.binarypackagename_id.is_in(
[bpn.id for bpn in binarypackagenames]
),
)