Merge ~cjwatson/launchpad:stormify-productlicense into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 3e0da72ddd49f8a38cda674c6a582ea65887f3d7
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:stormify-productlicense
Merge into: launchpad:master
Diff against target: 91 lines (+27/-12)
2 files modified
lib/lp/registry/model/product.py (+11/-7)
lib/lp/registry/model/productlicense.py (+16/-5)
Reviewer Review Type Date Requested Status
Simone Pelosi Approve
Review via email: mp+446320@code.launchpad.net

Commit message

Convert ProductLicense to Storm

To post a comment you must log in.
Revision history for this message
Simone Pelosi (pelpsi) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/product.py b/lib/lp/registry/model/product.py
2index 3c95e99..b879223 100644
3--- a/lib/lp/registry/model/product.py
4+++ b/lib/lp/registry/model/product.py
5@@ -906,8 +906,10 @@ class Product(
6 @cachedproperty
7 def _cached_licenses(self):
8 """Get the licenses as a tuple."""
9- product_licenses = ProductLicense.selectBy(
10- product=self, orderBy="license"
11+ product_licenses = (
12+ IStore(ProductLicense)
13+ .find(ProductLicense, product=self)
14+ .order_by(ProductLicense.license)
15 )
16 return tuple(
17 product_license.license for product_license in product_licenses
18@@ -939,8 +941,10 @@ class Product(
19 raise ValueError("%s is not a License." % license)
20
21 for license in old_licenses.difference(licenses):
22- product_license = ProductLicense.selectOneBy(
23- product=self, license=license
24+ product_license = (
25+ IStore(ProductLicense)
26+ .find(ProductLicense, product=self, license=license)
27+ .one()
28 )
29 product_license.destroySelf()
30
31@@ -1696,9 +1700,9 @@ def get_precached_products(
32 cache.commercial_subscription = subscription
33 if need_licences:
34 for license in IStore(ProductLicense).find(
35- ProductLicense, ProductLicense.productID.is_in(product_ids)
36+ ProductLicense, ProductLicense.product_id.is_in(product_ids)
37 ):
38- cache = caches[license.productID]
39+ cache = caches[license.product_id]
40 if license.license not in cache._cached_licenses:
41 cache._cached_licenses.append(license.license)
42 if need_projectgroups:
43@@ -2140,7 +2144,7 @@ class ProductSet:
44 1,
45 tables=[ProductLicense],
46 where=And(
47- ProductLicense.productID == Product.id,
48+ ProductLicense.product_id == Product.id,
49 ProductLicense.license.is_in(licenses),
50 ),
51 )
52diff --git a/lib/lp/registry/model/productlicense.py b/lib/lp/registry/model/productlicense.py
53index 8179e34..3f63b78 100644
54--- a/lib/lp/registry/model/productlicense.py
55+++ b/lib/lp/registry/model/productlicense.py
56@@ -7,19 +7,30 @@ __all__ = [
57 "ProductLicense",
58 ]
59
60-
61+from storm.locals import Int, Reference, Store
62 from zope.interface import implementer
63
64 from lp.registry.interfaces.product import License
65 from lp.registry.interfaces.productlicense import IProductLicense
66 from lp.services.database.enumcol import DBEnum
67-from lp.services.database.sqlbase import SQLBase
68-from lp.services.database.sqlobject import ForeignKey
69+from lp.services.database.stormbase import StormBase
70
71
72 @implementer(IProductLicense)
73-class ProductLicense(SQLBase):
74+class ProductLicense(StormBase):
75 """A product's licence."""
76
77- product = ForeignKey(dbName="product", foreignKey="Product", notNull=True)
78+ __storm_table__ = "ProductLicense"
79+
80+ id = Int(primary=True)
81+ product_id = Int(name="product", allow_none=False)
82+ product = Reference(product_id, "Product.id")
83 license = DBEnum(name="license", allow_none=False, enum=License)
84+
85+ def __init__(self, product, license):
86+ super().__init__()
87+ self.product = product
88+ self.license = license
89+
90+ def destroySelf(self):
91+ Store.of(self).remove(self)

Subscribers

People subscribed via source and target branches

to status/vote changes: