~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/model/sourcepackagerecipebuild.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-02 15:48:28 UTC
  • mfrom: (14513.2.4 builders-timeout-903827)
  • Revision ID: launchpad@pqm.canonical.com-20120102154828-r4echs7u11g99u8b
[r=adeuring][bug=903827] Cache objects prior to displaying builders'
        homepage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
            PackageBuild.build_farm_job_id == build_farm_job.id).one()
288
288
 
289
289
    @classmethod
 
290
    def preloadBuildsData(cls, builds):
 
291
        # Circular imports.
 
292
        from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
 
293
        package_builds = load_related(
 
294
            PackageBuild, builds, ['package_build_id'])
 
295
        archives = load_related(Archive, package_builds, ['archive_id'])
 
296
        load_related(Person, archives, ['ownerID'])
 
297
        sprs = load_related(
 
298
            SourcePackageRecipe, builds, ['recipe_id'])
 
299
        SourcePackageRecipe.preLoadDataForSourcePackageRecipes(sprs)
 
300
 
 
301
    @classmethod
290
302
    def getByBuildFarmJobs(cls, build_farm_jobs):
291
303
        """See `ISpecificBuildFarmJobSource`."""
292
304
        if len(build_farm_jobs) == 0:
294
306
        build_farm_job_ids = [
295
307
            build_farm_job.id for build_farm_job in build_farm_jobs]
296
308
 
297
 
        def eager_load(rows):
298
 
            # Circular imports.
299
 
            from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
300
 
            package_builds = load_related(
301
 
                PackageBuild, rows, ['package_build_id'])
302
 
            archives = load_related(Archive, package_builds, ['archive_id'])
303
 
            load_related(Person, archives, ['ownerID'])
304
 
            sprs = load_related(
305
 
                SourcePackageRecipe, rows, ['recipe_id'])
306
 
            SourcePackageRecipe.preLoadDataForSourcePackageRecipes(sprs)
307
309
        resultset = Store.of(build_farm_jobs[0]).find(cls,
308
310
            cls.package_build_id == PackageBuild.id,
309
311
            PackageBuild.build_farm_job_id.is_in(build_farm_job_ids))
310
 
        return DecoratedResultSet(resultset, pre_iter_hook=eager_load)
 
312
        return DecoratedResultSet(
 
313
            resultset, pre_iter_hook=cls.preloadBuildsData)
311
314
 
312
315
    @classmethod
313
316
    def getRecentBuilds(cls, requester, recipe, distroseries, _now=None):
428
431
        We override this to provide a delegate specific to package builds."""
429
432
        self.build_farm_job = BuildFarmBuildJob(self.build)
430
433
 
 
434
    @staticmethod
 
435
    def preloadBuildFarmJobs(jobs):
 
436
        from lp.code.model.sourcepackagerecipebuild import (
 
437
            SourcePackageRecipeBuild,
 
438
            )
 
439
        return list(IStore(SourcePackageRecipeBuildJob).find(
 
440
            SourcePackageRecipeBuild,
 
441
            [SourcePackageRecipeBuildJob.id.is_in([job.id for job in jobs]),
 
442
             SourcePackageRecipeBuildJob.build_id ==
 
443
                 SourcePackageRecipeBuild.id]))
 
444
 
 
445
    @classmethod
 
446
    def preloadJobsData(cls, jobs):
 
447
        load_related(Job, jobs, ['job_id'])
 
448
        builds = load_related(
 
449
            SourcePackageRecipeBuild, jobs, ['build_id'])
 
450
        SourcePackageRecipeBuild.preloadBuildsData(builds)
 
451
 
431
452
    @classmethod
432
453
    def new(cls, build, job):
433
454
        """See `ISourcePackageRecipeBuildJobSource`."""