Example #1
0
 def preloadBuildsData(cls, builds):
     # Circular imports.
     from lp.services.librarian.model import LibraryFileAlias
     # Load the related branches.
     branches = load_related(Branch, builds, ['branch_id'])
     # Preload branches' cached associated targets, product series, and
     # suite source packages for all the related branches.
     GenericBranchCollection.preloadDataForBranches(branches)
     load_related(LibraryFileAlias, builds, ['log_id'])
 def preloadJobsData(cls, jobs):
     # Circular imports.
     from lp.code.model.branch import Branch
     from lp.registry.model.product import Product
     from lp.code.model.branchcollection import GenericBranchCollection
     from lp.services.job.model.job import Job
     contexts = [job.context for job in jobs]
     load_related(Job, contexts, ['jobID'])
     branches = load_related(Branch, contexts, ['branchID'])
     GenericBranchCollection.preloadDataForBranches(branches)
     load_related(Product, branches, ['productID'])
 def preloadJobsData(cls, jobs):
     # Circular imports.
     from lp.code.model.branch import Branch
     from lp.registry.model.product import Product
     from lp.code.model.branchcollection import GenericBranchCollection
     from lp.services.job.model.job import Job
     contexts = [job.context for job in jobs]
     load_related(Job, contexts, ['jobID'])
     branches = load_related(Branch, contexts, ['branchID'])
     GenericBranchCollection.preloadDataForBranches(branches)
     load_related(Product, branches, ['productID'])
    def preloadDataForBMPs(branch_merge_proposals, user):
        # Utility to load the data related to a list of bmps.
        # Circular imports.
        from lp.code.model.branch import Branch
        from lp.code.model.branchcollection import GenericBranchCollection
        from lp.registry.model.product import Product
        from lp.registry.model.distroseries import DistroSeries

        ids = set()
        source_branch_ids = set()
        person_ids = set()
        for mp in branch_merge_proposals:
            ids.add(mp.id)
            source_branch_ids.add(mp.source_branchID)
            person_ids.add(mp.registrantID)
            person_ids.add(mp.merge_reporterID)

        branches = load_related(
            Branch, branch_merge_proposals, (
                "target_branchID", "prerequisite_branchID",
                "source_branchID"))
        # The stacked on branches are used to check branch visibility.
        GenericBranchCollection.preloadVisibleStackedOnBranches(
            branches, user)

        if len(branches) == 0:
            return

        # Pre-load PreviewDiffs and Diffs.
        preview_diffs = IStore(BranchMergeProposal).find(
            PreviewDiff,
            PreviewDiff.branch_merge_proposal_id.is_in(ids)).order_by(
                PreviewDiff.branch_merge_proposal_id,
                Desc(PreviewDiff.date_created)).config(
                    distinct=[PreviewDiff.branch_merge_proposal_id])
        load_related(Diff, preview_diffs, ['diff_id'])
        for previewdiff in preview_diffs:
            cache = get_property_cache(previewdiff.branch_merge_proposal)
            cache.preview_diff = previewdiff

        # Add source branch owners' to the list of pre-loaded persons.
        person_ids.update(
            branch.ownerID for branch in branches
            if branch.id in source_branch_ids)

        # Pre-load Person and ValidPersonCache.
        list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
            person_ids, need_validity=True))

        # Pre-load branches' data.
        load_related(SourcePackageName, branches, ['sourcepackagenameID'])
        load_related(DistroSeries, branches, ['distroseriesID'])
        load_related(Product, branches, ['productID'])
        GenericBranchCollection.preloadDataForBranches(branches)
 def preloadBuildsData(cls, builds):
     # Circular imports.
     from lp.services.librarian.model 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)
     load_related(LibraryFileAlias, builds, ['log_id'])
Example #6
0
    def preloadDataForBMPs(branch_merge_proposals, user):
        # Utility to load the data related to a list of bmps.
        # Circular imports.
        from lp.code.model.branch import Branch
        from lp.code.model.branchcollection import GenericBranchCollection
        from lp.registry.model.product import Product
        from lp.registry.model.distroseries import DistroSeries

        ids = set()
        source_branch_ids = set()
        person_ids = set()
        for mp in branch_merge_proposals:
            ids.add(mp.id)
            source_branch_ids.add(mp.source_branchID)
            person_ids.add(mp.registrantID)
            person_ids.add(mp.merge_reporterID)

        branches = load_related(
            Branch, branch_merge_proposals,
            ("target_branchID", "prerequisite_branchID", "source_branchID"))
        # The stacked on branches are used to check branch visibility.
        GenericBranchCollection.preloadVisibleStackedOnBranches(branches, user)

        if len(branches) == 0:
            return

        # Pre-load PreviewDiffs and Diffs.
        preview_diffs = IStore(BranchMergeProposal).find(
            PreviewDiff,
            PreviewDiff.branch_merge_proposal_id.is_in(ids)).order_by(
                PreviewDiff.branch_merge_proposal_id,
                Desc(PreviewDiff.date_created)).config(
                    distinct=[PreviewDiff.branch_merge_proposal_id])
        load_related(Diff, preview_diffs, ['diff_id'])
        for previewdiff in preview_diffs:
            cache = get_property_cache(previewdiff.branch_merge_proposal)
            cache.preview_diff = previewdiff

        # Add source branch owners' to the list of pre-loaded persons.
        person_ids.update(branch.ownerID for branch in branches
                          if branch.id in source_branch_ids)

        # Pre-load Person and ValidPersonCache.
        list(
            getUtility(IPersonSet).getPrecachedPersonsFromIDs(
                person_ids, need_validity=True))

        # Pre-load branches' data.
        load_related(SourcePackageName, branches, ['sourcepackagenameID'])
        load_related(DistroSeries, branches, ['distroseriesID'])
        load_related(Product, branches, ['productID'])
        GenericBranchCollection.preloadDataForBranches(branches)
 def preLoadReferencedBranches(sourcepackagerecipedatas):
     # Circular imports.
     from lp.code.model.branchcollection import GenericBranchCollection
     from lp.code.model.gitcollection import GenericGitCollection
     # Load the related Branch, _SourcePackageRecipeDataInstruction.
     base_branches = load_related(Branch, sourcepackagerecipedatas,
                                  ['base_branch_id'])
     base_repositories = load_related(GitRepository,
                                      sourcepackagerecipedatas,
                                      ['base_git_repository_id'])
     sprd_instructions = load_referencing(
         _SourcePackageRecipeDataInstruction, sourcepackagerecipedatas,
         ['recipe_data_id'])
     sub_branches = load_related(Branch, sprd_instructions, ['branch_id'])
     sub_repositories = load_related(GitRepository, sprd_instructions,
                                     ['git_repository_id'])
     all_branches = base_branches + sub_branches
     all_repositories = base_repositories + sub_repositories
     # Pre-load branches'/repositories' data.
     if all_branches:
         GenericBranchCollection.preloadDataForBranches(all_branches)
     if all_repositories:
         GenericGitCollection.preloadDataForRepositories(all_repositories)
     # Store the pre-fetched objects on the sourcepackagerecipedatas
     # objects.
     branch_to_recipe_data = {
         instr.branch_id: instr.recipe_data_id
         for instr in sprd_instructions if instr.branch_id is not None
     }
     repository_to_recipe_data = {
         instr.git_repository_id: instr.recipe_data_id
         for instr in sprd_instructions
         if instr.git_repository_id is not None
     }
     caches = {
         sprd.id: [sprd, get_property_cache(sprd)]
         for sprd in sourcepackagerecipedatas
     }
     for _, [sprd, cache] in caches.items():
         cache._referenced_branches = [sprd.base]
     for branch in sub_branches:
         cache = caches[branch_to_recipe_data[branch.id]][1]
         cache._referenced_branches.append(branch)
     for repository in sub_repositories:
         cache = caches[repository_to_recipe_data[repository.id]][1]
         cache._referenced_branches.append(repository)