← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-translationtemplateitem into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-translationtemplateitem into launchpad:master.

Commit message:
Convert TranslationTemplateItem to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/446326
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-translationtemplateitem into launchpad:master.
diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
index 86adeaa..57dc83a 100644
--- a/lib/lp/scripts/garbo.py
+++ b/lib/lp/scripts/garbo.py
@@ -1618,7 +1618,7 @@ class UnusedPOTMsgSetPruner(TunableLoop):
         store = IPrimaryStore(POTMsgSet)
         related_ttis = store.find(
             TranslationTemplateItem,
-            In(TranslationTemplateItem.potmsgsetID, msgset_ids_to_remove),
+            In(TranslationTemplateItem.potmsgset_id, msgset_ids_to_remove),
         )
         related_ttis.remove()
         # Remove related TranslationMessages.
diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
index 3e92ec0..71d302f 100644
--- a/lib/lp/scripts/tests/test_garbo.py
+++ b/lib/lp/scripts/tests/test_garbo.py
@@ -1399,7 +1399,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
         test_ids = list(potmsgset_pofile)
         obsolete_msgsets = store.find(
             POTMsgSet,
-            In(TranslationTemplateItem.potmsgsetID, test_ids),
+            In(TranslationTemplateItem.potmsgset_id, test_ids),
             TranslationTemplateItem.sequence == 0,
         )
         self.assertEqual(4, obsolete_msgsets.count())
@@ -1420,7 +1420,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
         pruner(2)
         self.assertEqual(0, obsolete_msgsets.count())
         preserved_msgsets = store.find(
-            POTMsgSet, In(TranslationTemplateItem.potmsgsetID, test_ids)
+            POTMsgSet, In(TranslationTemplateItem.potmsgset_id, test_ids)
         )
         self.assertEqual(1, preserved_msgsets.count())
 
diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py
index 8d09c17..6539f65 100644
--- a/lib/lp/translations/model/pofile.py
+++ b/lib/lp/translations/model/pofile.py
@@ -155,7 +155,7 @@ class POFileMixIn(RosettaStats):
                         Join(
                             TranslationTemplateItem,
                             tm_ids.potmsgsetID
-                            == TranslationTemplateItem.potmsgsetID,
+                            == TranslationTemplateItem.potmsgset_id,
                         ),
                     ),
                     where=And(
@@ -181,7 +181,7 @@ class POFileMixIn(RosettaStats):
                 Join(
                     TranslationTemplateItem,
                     TranslationMessage.potmsgset
-                    == TranslationTemplateItem.potmsgsetID,
+                    == TranslationTemplateItem.potmsgset_id,
                 ),
             ),
             where=And(
@@ -389,7 +389,7 @@ class POFile(SQLBase, POFileMixIn):
             TranslationMessage.potemplateID, self.potemplate.id
         )
         clauses = [
-            TranslationTemplateItem.potmsgsetID
+            TranslationTemplateItem.potmsgset_id
             == TranslationMessage.potmsgsetID,
             TranslationTemplateItem.potemplate == self.potemplate,
             TranslationMessage.language == self.language,
@@ -535,7 +535,7 @@ class POFile(SQLBase, POFileMixIn):
         clauses = [
             TranslationTemplateItem.potemplate == self.potemplate,
             (
-                TranslationTemplateItem.potmsgsetID
+                TranslationTemplateItem.potmsgset_id
                 == TranslationMessage.potmsgsetID
             ),
             TranslationMessage.language == self.language,
@@ -612,7 +612,7 @@ class POFile(SQLBase, POFileMixIn):
         """See `IPOFile`."""
         clauses, clause_tables = self._getTranslatedMessagesQuery()
         query = And(
-            TranslationTemplateItem.potmsgsetID == POTMsgSet.id, *clauses
+            TranslationTemplateItem.potmsgset_id == POTMsgSet.id, *clauses
         )
         clause_tables.insert(0, POTMsgSet)
         return self._getOrderedPOTMsgSets(clause_tables, query)
@@ -631,17 +631,17 @@ class POFile(SQLBase, POFileMixIn):
                 # staging we get more than a 10x speed improvement: from
                 # 8s to 0.7s).  We also need to put it before any other
                 # clauses to be actually useful.
-                TranslationTemplateItem.potmsgsetID
-                == TranslationTemplateItem.potmsgsetID,
-                POTMsgSet.id == TranslationTemplateItem.potmsgsetID,
+                TranslationTemplateItem.potmsgset_id
+                == TranslationTemplateItem.potmsgset_id,
+                POTMsgSet.id == TranslationTemplateItem.potmsgset_id,
                 *translated_clauses,
             ),
         )
         clauses = [
-            TranslationTemplateItem.potemplateID == self.potemplate.id,
-            TranslationTemplateItem.potmsgsetID == POTMsgSet.id,
+            TranslationTemplateItem.potemplate_id == self.potemplate.id,
+            TranslationTemplateItem.potmsgset_id == POTMsgSet.id,
             TranslationTemplateItem.sequence > 0,
-            Not(TranslationTemplateItem.potmsgsetID.is_in(translated_query)),
+            Not(TranslationTemplateItem.potmsgset_id.is_in(translated_query)),
         ]
         return self._getOrderedPOTMsgSets(
             [POTMsgSet, TranslationTemplateItem], And(*clauses)
@@ -663,7 +663,7 @@ class POFile(SQLBase, POFileMixIn):
         )
         clauses.extend(
             [
-                TranslationTemplateItem.potmsgsetID == POTMsgSet.id,
+                TranslationTemplateItem.potmsgset_id == POTMsgSet.id,
                 Not(getattr(TranslationMessage, flag_name)),
                 msgstr_clause,
             ]
@@ -718,8 +718,8 @@ class POFile(SQLBase, POFileMixIn):
                     distinct=True,
                 )
             ),
-            POTMsgSet.id == TranslationTemplateItem.potmsgsetID,
-            TranslationTemplateItem.potemplateID == self.potemplate.id,
+            POTMsgSet.id == TranslationTemplateItem.potmsgset_id,
+            TranslationTemplateItem.potemplate_id == self.potemplate.id,
         )
         return self._getOrderedPOTMsgSets(
             [POTMsgSet, TranslationTemplateItem], query
@@ -739,7 +739,7 @@ class POFile(SQLBase, POFileMixIn):
         )
         clauses.extend(
             [
-                TranslationTemplateItem.potmsgsetID == POTMsgSet.id,
+                TranslationTemplateItem.potmsgset_id == POTMsgSet.id,
                 Not(getattr(TranslationMessage, other_side_flag_name)),
             ]
         )
@@ -1626,8 +1626,8 @@ class POFileSet:
         from lp.translations.model.potemplate import POTemplate
 
         clauses = [
-            TranslationTemplateItem.potemplateID == POFile.potemplateID,
-            POTMsgSet.id == TranslationTemplateItem.potmsgsetID,
+            TranslationTemplateItem.potemplate_id == POFile.potemplateID,
+            POTMsgSet.id == TranslationTemplateItem.potmsgset_id,
             POTMsgSet.msgid_singular == POMsgID.id,
             POMsgID.msgid.is_in(POTMsgSet.credits_message_ids),
         ]
diff --git a/lib/lp/translations/model/potemplate.py b/lib/lp/translations/model/potemplate.py
index e5a986f..3c293e4 100644
--- a/lib/lp/translations/model/potemplate.py
+++ b/lib/lp/translations/model/potemplate.py
@@ -488,8 +488,8 @@ class POTemplate(SQLBase, RosettaStats):
         """Return SQL clauses for finding POTMsgSets which belong
         to this POTemplate."""
         clauses = [
-            TranslationTemplateItem.potemplateID == self.id,
-            TranslationTemplateItem.potmsgsetID == POTMsgSet.id,
+            TranslationTemplateItem.potemplate_id == self.id,
+            TranslationTemplateItem.potmsgset_id == POTMsgSet.id,
         ]
         return clauses
 
@@ -697,17 +697,17 @@ class POTemplate(SQLBase, RosettaStats):
         POTMsgSet, look through sharing templates as well.
         """
         clauses = [
-            TranslationTemplateItem.potmsgsetID == POTMsgSet.id,
+            TranslationTemplateItem.potmsgset_id == POTMsgSet.id,
             POTMsgSet.msgid_singular == msgid_singular,
             POTMsgSet.msgid_plural == msgid_plural,
             POTMsgSet.context == context,
         ]
         if sharing_templates:
             clauses.append(
-                TranslationTemplateItem.potemplateID.is_in(self._sharing_ids)
+                TranslationTemplateItem.potemplate_id.is_in(self._sharing_ids)
             )
         else:
-            clauses.append(TranslationTemplateItem.potemplateID == self.id)
+            clauses.append(TranslationTemplateItem.potemplate_id == self.id)
 
         # If there are multiple messages, make the one from the
         # current POTemplate be returned first.
@@ -1137,7 +1137,7 @@ class POTemplate(SQLBase, RosettaStats):
         rows = source.find(
             (TranslationTemplateItem, POTMsgSet, Singular, Plural),
             TranslationTemplateItem.potemplate == self,
-            POTMsgSet.id == TranslationTemplateItem.potmsgsetID,
+            POTMsgSet.id == TranslationTemplateItem.potmsgset_id,
         )
 
         rows = rows.order_by(TranslationTemplateItem.sequence)
diff --git a/lib/lp/translations/model/translationmessage.py b/lib/lp/translations/model/translationmessage.py
index 044cc6a..25403fb 100644
--- a/lib/lp/translations/model/translationmessage.py
+++ b/lib/lp/translations/model/translationmessage.py
@@ -680,17 +680,17 @@ class TranslationMessageSet:
             IStore(POFile)
             .find(
                 (
-                    TranslationTemplateItem.potmsgsetID,
+                    TranslationTemplateItem.potmsgset_id,
                     POFile.id,
                     TranslationTemplateItem.sequence,
                 ),
-                TranslationTemplateItem.potmsgsetID.is_in(
+                TranslationTemplateItem.potmsgset_id.is_in(
                     message.potmsgsetID for message in messages
                 ),
-                POFile.potemplateID == TranslationTemplateItem.potemplateID,
+                POFile.potemplateID == TranslationTemplateItem.potemplate_id,
                 *pofile_constraints,
             )
-            .config(distinct=(TranslationTemplateItem.potmsgsetID,))
+            .config(distinct=(TranslationTemplateItem.potmsgset_id,))
         )
         potmsgset_map = {
             potmsgset_id: (pofile_id, sequence)
diff --git a/lib/lp/translations/model/translationtemplateitem.py b/lib/lp/translations/model/translationtemplateitem.py
index 7198a3e..c79aff6 100644
--- a/lib/lp/translations/model/translationtemplateitem.py
+++ b/lib/lp/translations/model/translationtemplateitem.py
@@ -5,25 +5,33 @@ __all__ = [
     "TranslationTemplateItem",
 ]
 
+from storm.locals import Int, Reference, Store
 from zope.interface import implementer
 
-from lp.services.database.sqlbase import SQLBase
-from lp.services.database.sqlobject import ForeignKey, IntCol
+from lp.services.database.stormbase import StormBase
 from lp.translations.interfaces.translationtemplateitem import (
     ITranslationTemplateItem,
 )
 
 
 @implementer(ITranslationTemplateItem)
-class TranslationTemplateItem(SQLBase):
+class TranslationTemplateItem(StormBase):
     """See `ITranslationTemplateItem`."""
 
-    _table = "TranslationTemplateItem"
+    __storm_table__ = "TranslationTemplateItem"
 
-    potemplate = ForeignKey(
-        foreignKey="POTemplate", dbName="potemplate", notNull=True
-    )
-    sequence = IntCol(dbName="sequence", notNull=True)
-    potmsgset = ForeignKey(
-        foreignKey="POTMsgSet", dbName="potmsgset", notNull=True
-    )
+    id = Int(primary=True)
+    potemplate_id = Int(name="potemplate", allow_none=False)
+    potemplate = Reference(potemplate_id, "POTemplate.id")
+    sequence = Int(name="sequence", allow_none=False)
+    potmsgset_id = Int(name="potmsgset", allow_none=False)
+    potmsgset = Reference(potmsgset_id, "POTMsgSet.id")
+
+    def __init__(self, potemplate, sequence, potmsgset):
+        super().__init__()
+        self.potemplate = potemplate
+        self.sequence = sequence
+        self.potmsgset = potmsgset
+
+    def destroySelf(self):
+        Store.of(self).remove(self)
diff --git a/lib/lp/translations/scripts/migrate_current_flag.py b/lib/lp/translations/scripts/migrate_current_flag.py
index 9b5bb46..0b09102 100644
--- a/lib/lp/translations/scripts/migrate_current_flag.py
+++ b/lib/lp/translations/scripts/migrate_current_flag.py
@@ -148,9 +148,9 @@ class MigrateCurrentFlagProcess:
             TranslationMessage.is_current_upstream == False,
             (
                 TranslationMessage.potmsgsetID
-                == TranslationTemplateItem.potmsgsetID
+                == TranslationTemplateItem.potmsgset_id
             ),
-            TranslationTemplateItem.potemplateID == POTemplate.id,
+            TranslationTemplateItem.potemplate_id == POTemplate.id,
             POTemplate.productseriesID == ProductSeries.id,
             ProductSeries.productID == product.id,
         ).config(distinct=True)
diff --git a/lib/lp/translations/scripts/scrub_pofiletranslator.py b/lib/lp/translations/scripts/scrub_pofiletranslator.py
index fbf8add..7aa0cb1 100644
--- a/lib/lp/translations/scripts/scrub_pofiletranslator.py
+++ b/lib/lp/translations/scripts/scrub_pofiletranslator.py
@@ -68,8 +68,8 @@ def get_potmsgset_ids(potemplate_id):
     store = IStore(POTemplate)
     return set(
         store.find(
-            TranslationTemplateItem.potmsgsetID,
-            TranslationTemplateItem.potemplateID == potemplate_id,
+            TranslationTemplateItem.potmsgset_id,
+            TranslationTemplateItem.potemplate_id == potemplate_id,
             TranslationTemplateItem.sequence > 0,
         )
     )
diff --git a/lib/lp/translations/utilities/translationsplitter.py b/lib/lp/translations/utilities/translationsplitter.py
index 5dcb5cc..d4503b9 100644
--- a/lib/lp/translations/utilities/translationsplitter.py
+++ b/lib/lp/translations/utilities/translationsplitter.py
@@ -103,13 +103,13 @@ class TranslationSplitter(TranslationSplitterBase):
         UbuntuTemplate = ClassAlias(POTemplate, "UbuntuTemplate")
         return store.find(
             (UpstreamItem, UbuntuItem),
-            UpstreamItem.potmsgsetID == UbuntuItem.potmsgsetID,
-            UbuntuItem.potemplateID == UbuntuTemplate.id,
+            UpstreamItem.potmsgset_id == UbuntuItem.potmsgset_id,
+            UbuntuItem.potemplate_id == UbuntuTemplate.id,
             UbuntuTemplate.sourcepackagenameID
             == self.sourcepackage.sourcepackagename.id,
             UbuntuTemplate.distroseriesID
             == self.sourcepackage.distroseries.id,
-            UpstreamItem.potemplateID == UpstreamTemplate.id,
+            UpstreamItem.potemplate_id == UpstreamTemplate.id,
             UpstreamTemplate.productseriesID == self.productseries.id,
         )
 
@@ -151,7 +151,7 @@ class TranslationTemplateSplitter(TranslationSplitterBase):
         OtherItem = ClassAlias(TranslationTemplateItem, "OtherItem")
         return Store.of(self.potemplate).find(
             (OtherItem, ThisItem),
-            ThisItem.potemplateID == self.potemplate.id,
-            OtherItem.potmsgsetID == ThisItem.potmsgsetID,
-            Not(OtherItem.potemplateID.is_in(sharing_ids)),
+            ThisItem.potemplate_id == self.potemplate.id,
+            OtherItem.potmsgset_id == ThisItem.potmsgset_id,
+            Not(OtherItem.potemplate_id.is_in(sharing_ids)),
         )