← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/denorm-bspph-garbo into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/denorm-bspph-garbo into lp:launchpad with lp:~stevenk/launchpad/denorm-bspph-model as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/denorm-bspph-garbo/+merge/75118

Add a garbo job that will populate BPPH.binarypackagename and SPPH.sourcepackagename.
-- 
https://code.launchpad.net/~stevenk/launchpad/denorm-bspph-garbo/+merge/75118
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/denorm-bspph-garbo into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2011-09-12 21:08:41 +0000
+++ database/schema/security.cfg	2011-09-14 01:26:31 +0000
@@ -2151,6 +2151,9 @@
 groups=script,read
 public.answercontact                    = SELECT, DELETE
 public.branchjob                        = SELECT, DELETE
+public.binarypackagename                = SELECT
+public.binarypackagerelease             = SELECT
+public.binarypackagepublishinghistory   = SELECT, UPDATE
 public.bug                              = SELECT, UPDATE
 public.bugaffectsperson                 = SELECT
 public.bugattachment                    = SELECT, DELETE
@@ -2184,6 +2187,9 @@
 public.potmsgset                        = SELECT, DELETE
 public.revisionauthor                   = SELECT, UPDATE
 public.revisioncache                    = SELECT, DELETE
+public.sourcepackagename                = SELECT
+public.sourcepackagerelease             = SELECT
+public.sourcepackagepublishinghistory   = SELECT, UPDATE
 public.suggestivepotemplate             = INSERT, DELETE
 public.teamparticipation                = SELECT, DELETE
 public.translationmessage               = SELECT, DELETE

=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py	2011-09-13 09:15:40 +0000
+++ lib/lp/scripts/garbo.py	2011-09-14 01:26:31 +0000
@@ -86,6 +86,10 @@
     SilentLaunchpadScriptFailure,
     )
 from lp.services.session.model import SessionData
+from lp.soyuz.model.publishing import (
+    BinaryPackagePublishingHistory,
+    SourcePackagePublishingHistory,
+    )
 from lp.translations.interfaces.potemplate import IPOTemplateSet
 from lp.translations.model.potranslation import POTranslation
 from lp.translations.model.potmsgset import POTMsgSet
@@ -950,6 +954,57 @@
         transaction.commit()
 
 
+class SourcePackagePublishingHistorySPNPopulator(TunableLoop):
+    offset = 0
+    maximum_chunk_size = 5000
+
+    def findSPPHs(self, offset):
+        store = IMasterStore(SourcePackagePublishingHistory)
+        return store.find(SourcePackagePublishingHistory,
+            SourcePackagePublishingHistory.sourcepackagename == None,
+            SourcePackagePublishingHistory.id >= self.offset
+            ).order_by(SourcePackagePublishingHistory.id)
+
+    def isDone(self):
+        """See `TunableLoop`."""
+        return self.findSPPHs(0).is_empty()
+
+    def __call__(self, chunk_size):
+        """See `TunableLoop`."""
+        spphs = self.findSPPHs(self.offset)[:chunk_size]
+        for spph in spphs:
+            spph.sourcepackagename = (
+                spph.sourcepackagerelease.sourcepackagename)
+        self.offset += chunk_size
+        transaction.commit()
+
+
+class BinaryPackagePublishingHistoryBPNPopulator(TunableLoop):
+    done = False
+    offset = 0
+    maximum_chunk_size = 5000
+
+    def findBPPHs(self, offset):
+        store = IMasterStore(BinaryPackagePublishingHistory)
+        return store.find(BinaryPackagePublishingHistory,
+            BinaryPackagePublishingHistory.binarypackagename == None,
+            BinaryPackagePublishingHistory.id >= self.offset
+            ).order_by(BinaryPackagePublishingHistory.id)
+
+    def isDone(self):
+        """See `TunableLoop`."""
+        return self.findBPPHs(0).is_empty()
+
+    def __call__(self, chunk_size):
+        """See `TunableLoop`."""
+        bpphs = self.findBPPHs(self.offset)[:chunk_size]
+        for bpph in bpphs:
+            bpph.binarypackagename = (
+                bpph.binarypackagerelease.binarypackagename)
+        self.offset += chunk_size
+        transaction.commit()
+
+
 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
     """Abstract base class to run a collection of TunableLoops."""
     script_name = None  # Script name for locking and database user. Override.
@@ -1199,6 +1254,8 @@
         UnusedSessionPruner,
         DuplicateSessionPruner,
         BugHeatUpdater,
+        SourcePackagePublishingHistorySPNPopulator,
+        BinaryPackagePublishingHistoryBPNPopulator,
         ]
     experimental_tunable_loops = []
 

=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py	2011-09-09 13:19:24 +0000
+++ lib/lp/scripts/tests/test_garbo.py	2011-09-14 01:26:31 +0000
@@ -1022,3 +1022,27 @@
         self.assertNotEqual(0, unreferenced_msgsets.count())
         self.runDaily()
         self.assertEqual(0, unreferenced_msgsets.count())
+
+    def test_SourcePackagePublishingHistorySPNPopulator(self):
+        # If SPPHs do not have sourcepackagename set, the populator will set
+        # it.
+        LaunchpadZopelessLayer.switchDbUser('testadmin')
+        spph = self.factory.makeSourcePackagePublishingHistory()
+        spn = spph.sourcepackagename
+        spph.sourcepackagenameID = None
+        transaction.commit()
+        self.assertIs(None, spph.sourcepackagename)
+        self.runHourly()
+        self.assertEqual(spn, spph.sourcepackagename)
+
+    def test_BinaryPackagePublishingHistoryBPNPopulator(self):
+        # If BPPHs do not have binarypackagename set, the populator will set
+        # it.
+        LaunchpadZopelessLayer.switchDbUser('testadmin')
+        bpph = self.factory.makeBinaryPackagePublishingHistory()
+        bpn = bpph.binarypackagename
+        bpph.binarypackagenameID = None
+        transaction.commit()
+        self.assertIs(None, bpph.binarypackagename)
+        self.runHourly()
+        self.assertEqual(bpn, bpph.binarypackagename)