~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-18 16:07:28 UTC
  • mfrom: (14301.3.6 activereviews-bug-867941)
  • Revision ID: launchpad@pqm.canonical.com-20111118160728-22t4cdvequz59pqh
[r=allenap][bug=867941][incr] Eager load stuff to improve the
 performance of a person's activereviews page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    PreviewDiff,
70
70
    )
71
71
from lp.code.model.seriessourcepackagebranch import SeriesSourcePackageBranch
 
72
from lp.registry.interfaces.person import IPersonSet
72
73
from lp.registry.model.distribution import Distribution
73
74
from lp.registry.model.distroseries import DistroSeries
74
75
from lp.registry.model.person import (
400
401
        # limited by the defined collection.
401
402
        owned = self.ownedBy(person).getMergeProposals(status)
402
403
        reviewing = self.getMergeProposalsForReviewer(person, status)
403
 
        return owned.union(reviewing)
 
404
        resultset = owned.union(reviewing)
 
405
 
 
406
        def do_eager_load(rows):
 
407
            source_branches = load_related(Branch, rows, ['source_branchID'])
 
408
            # Cache person's data (registrants of the proposal and
 
409
            # owners of the source branches).
 
410
            person_ids = set().union(
 
411
                (proposal.registrantID for proposal in rows),
 
412
                (branch.ownerID for branch in source_branches))
 
413
            list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
 
414
                person_ids, need_validity=True))
 
415
            # Load the source/target branches and preload the data for
 
416
            # these branches.
 
417
            target_branches = load_related(Branch, rows, ['target_branchID'])
 
418
            self._preloadDataForBranches(target_branches + source_branches)
 
419
            load_related(Product, target_branches, ['productID'])
 
420
 
 
421
        return DecoratedResultSet(resultset, pre_iter_hook=do_eager_load)
404
422
 
405
423
    def getMergeProposalsForReviewer(self, reviewer, status=None):
406
424
        """See `IBranchCollection`."""