← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/launchpad/builder-history-lfa into lp:launchpad

 

Raphaël Badin has proposed merging lp:~rvb/launchpad/builder-history-lfa into lp:launchpad with lp:~rvb/launchpad/builder-history-bug-890326 as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #905380 in Launchpad itself: "builder/+history issues repeated statements to fetch libraryfilealias objects."
  https://bugs.launchpad.net/launchpad/+bug/905380

For more details, see:
https://code.launchpad.net/~rvb/launchpad/builder-history-lfa/+merge/86071

This branch adds the prefetching of LibraryFileAlias objects to {sourcepackagerecipebuild, translationtemplatesbuild}preloadBuildsData.

= Tests =
(modified tests)
./bin/test -vvc test_builder_views test_build_history

= Q/A =
Find a builder/+history page and make sure that this query http://paste.ubuntu.com/772360/ is not among the repeated statements.
-- 
https://code.launchpad.net/~rvb/launchpad/builder-history-lfa/+merge/86071
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/builder-history-lfa into lp:launchpad.
=== modified file 'lib/lp/code/model/sourcepackagerecipebuild.py'
--- lib/lp/code/model/sourcepackagerecipebuild.py	2011-12-16 16:13:27 +0000
+++ lib/lp/code/model/sourcepackagerecipebuild.py	2011-12-16 16:13:27 +0000
@@ -310,9 +310,13 @@
     def preloadBuildsData(cls, builds):
         # Circular imports.
         from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
+        from canonical.launchpad.database.librarian import LibraryFileAlias
         SourcePackageRecipeBuild.prefetchBuildqueueRecord(builds)
         package_builds = load_related(
             PackageBuild, builds, ['package_build_id'])
+        build_farm_jobs = [
+            build.build_farm_job for build in builds]
+        load_related(LibraryFileAlias, build_farm_jobs, ['log_id'])
         archives = load_related(Archive, package_builds, ['archive_id'])
         load_related(Person, archives, ['ownerID'])
         sprs = load_related(

=== modified file 'lib/lp/soyuz/browser/tests/test_builder_views.py'
--- lib/lp/soyuz/browser/tests/test_builder_views.py	2011-12-16 16:13:27 +0000
+++ lib/lp/soyuz/browser/tests/test_builder_views.py	2011-12-16 16:13:27 +0000
@@ -18,7 +18,10 @@
 from canonical.launchpad.ftests import login
 from canonical.launchpad.webapp.servers import LaunchpadTestRequest
 from canonical.testing.layers import LaunchpadFunctionalLayer
-from lp.buildmaster.enums import BuildFarmJobType
+from lp.buildmaster.enums import (
+    BuildFarmJobType,
+    BuildStatus,
+    )
 from lp.buildmaster.interfaces.buildfarmjob import (
     IBuildFarmJobSource,
     InconsistentBuildFarmJobError,
@@ -158,6 +161,16 @@
 
 class BuildCreationMixin(object):
 
+    def markAsBuilt(self, build):
+        lfa = self.factory.makeLibraryFileAlias()
+        naked_build = removeSecurityProxy(build)
+        naked_build.log = lfa
+        naked_build.date_started = self.factory.getUniqueDate()
+        naked_build.date_finished = self.factory.getUniqueDate()
+        naked_build.status = BuildStatus.FULLYBUILT
+        import transaction
+        transaction.commit()
+
     def createTranslationTemplateBuildWithBuilder(self, builder=None):
         if builder is None:
             builder = self.factory.makeBuilder()
@@ -168,7 +181,7 @@
         branch = self.factory.makeBranch()
         build = source.create(build_farm_job, branch)
         removeSecurityProxy(build).builder = builder
-        self.addFakeBuildLog(build)
+        self.markAsBuilt(build)
         return build
 
     def createRecipeBuildWithBuilder(self, private_branch=False,
@@ -187,15 +200,9 @@
                     True, getUtility(IPersonSet).getByEmail(ADMIN_EMAIL))
         Store.of(build).flush()
         removeSecurityProxy(build).builder = builder
-        self.addFakeBuildLog(build)
+        self.markAsBuilt(build)
         return build
 
-    def addFakeBuildLog(self, build):
-        lfa = self.factory.makeLibraryFileAlias('mybuildlog.txt')
-        removeSecurityProxy(build).log = lfa
-        import transaction
-        transaction.commit()
-
     def createBinaryPackageBuild(self, in_ppa=False, builder=None):
         if builder is None:
             builder = self.factory.makeBuilder()
@@ -207,7 +214,7 @@
         naked_build.builder = builder
         naked_build.date_started = self.factory.getUniqueDate()
         naked_build.date_finished = self.factory.getUniqueDate()
-        self.addFakeBuildLog(build)
+        self.markAsBuilt(build)
         return build
 
 

=== modified file 'lib/lp/translations/model/translationtemplatesbuild.py'
--- lib/lp/translations/model/translationtemplatesbuild.py	2011-11-24 12:36:57 +0000
+++ lib/lp/translations/model/translationtemplatesbuild.py	2011-12-16 16:13:27 +0000
@@ -119,21 +119,28 @@
         """See `ITranslationTemplatesBuildSource`."""
         store = cls._getStore(store)
 
-        def eager_load(rows):
-            # Load the related branches, products.
-            branches = load_related(
-                Branch, rows, ['branch_id'])
-            load_related(
-                Product, branches, ['productID'])
-            # Preload branches cached associated product series and
-            # suite source packages for all the related branches.
-            GenericBranchCollection.preloadDataForBranches(branches)
-
         resultset = store.find(
             TranslationTemplatesBuild,
             TranslationTemplatesBuild.build_farm_job_id.is_in(
                 buildfarmjob_ids))
-        return DecoratedResultSet(resultset, pre_iter_hook=eager_load)
+        return DecoratedResultSet(
+            resultset, pre_iter_hook=cls.preloadBuildsData)
+
+    @classmethod
+    def preloadBuildsData(cls, builds):
+        # Circular imports.
+        from canonical.launchpad.database.librarian import LibraryFileAlias
+        # Load the related branches, products.
+        branches = load_related(
+            Branch, builds, ['branch_id'])
+        load_related(
+            Product, branches, ['productID'])
+        # Preload branches cached associated product series and
+        # suite source packages for all the related branches.
+        GenericBranchCollection.preloadDataForBranches(branches)
+        build_farm_jobs = [
+            build.build_farm_job for build in builds]
+        load_related(LibraryFileAlias, build_farm_jobs, ['log_id'])
 
     @classmethod
     def findByBranch(cls, branch, store=None):