~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/binarypackagebuild.py

[r=benji][bug=887078] Eager loads the objects related to a
 translation template build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    PackageBuild,
79
79
    PackageBuildDerived,
80
80
    )
 
81
from lp.services.database.bulk import load_related
81
82
from lp.services.job.model.job import Job
82
83
from lp.services.mail.sendmail import (
83
84
    format_address,
873
874
        clause_tables = (BinaryPackageBuild, PackageBuild, BuildFarmJob)
874
875
        build_farm_job_ids = [
875
876
            build_farm_job.id for build_farm_job in build_farm_jobs]
876
 
        return Store.of(build_farm_jobs[0]).using(*clause_tables).find(
 
877
 
 
878
        def eager_load(rows):
 
879
            # Circular imports.
 
880
            from lp.registry.model.sourcepackagename import (
 
881
                SourcePackageName
 
882
                )
 
883
            from lp.soyuz.model.sourcepackagerelease import (
 
884
                SourcePackageRelease
 
885
                )
 
886
            from lp.soyuz.model.distroarchseries import (
 
887
                DistroArchSeries
 
888
                )
 
889
            from lp.registry.model.distroseries import (
 
890
                DistroSeries
 
891
                )
 
892
            from lp.registry.model.distribution import (
 
893
                Distribution
 
894
                )
 
895
            from lp.soyuz.model.archive import Archive
 
896
            sprs = load_related(
 
897
                SourcePackageRelease, rows, ['source_package_release_id'])
 
898
            load_related(
 
899
                SourcePackageName, sprs, ['sourcepackagenameID'])
 
900
            distro_arch_series = load_related(
 
901
                DistroArchSeries, rows, ['distro_arch_series_id'])
 
902
            package_builds = load_related(
 
903
                PackageBuild, rows, ['package_build_id'])
 
904
            load_related(
 
905
                Archive, package_builds, ['archive_id'])
 
906
            distroseries = load_related(
 
907
                DistroSeries, distro_arch_series, ['distroseriesID'])
 
908
            load_related(
 
909
                Distribution, distroseries, ['distributionID'])
 
910
        resultset = Store.of(build_farm_jobs[0]).using(*clause_tables).find(
877
911
            BinaryPackageBuild,
878
912
            BinaryPackageBuild.package_build == PackageBuild.id,
879
913
            PackageBuild.build_farm_job == BuildFarmJob.id,
880
914
            BuildFarmJob.id.is_in(build_farm_job_ids))
 
915
        return DecoratedResultSet(resultset, pre_iter_hook=eager_load)
881
916
 
882
917
    def getPendingBuildsForArchSet(self, archseries):
883
918
        """See `IBinaryPackageBuildSet`."""