~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/browser/tests/test_bugtask.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-29 23:09:37 UTC
  • mfrom: (13814.1.1 bug724025)
  • Revision ID: launchpad@pqm.canonical.com-20110829230937-ugrcoxhl7mfn5zov
[incr] [r=lifeless][bug=724025] Reduce queries when you have several
        branches for a bug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
                self.factory.makeBugAttachment(bug=task.bug)
125
125
        self.assertThat(task, browses_under_limit)
126
126
 
 
127
    def test_rendered_query_counts_reduced_with_branches(self):
 
128
        f = self.factory
 
129
        owner = f.makePerson()
 
130
        ds = f.makeDistroSeries()
 
131
        sourcepackagenames = [
 
132
            f.makeSourcePackageName('testsourcepackagename%d' % i)
 
133
            for i in range(10)]
 
134
        sourcepackages = [
 
135
            f.makeSourcePackage(
 
136
                sourcepackagename=name, distroseries=ds, publish=True)
 
137
            for name in sourcepackagenames]
 
138
        bug = f.makeBug()
 
139
        bugtasks = []
 
140
        for sp in sourcepackages:
 
141
            bugtask = f.makeBugTask(bug=bug, owner=owner, target=sp)
 
142
            bugtasks.append(bugtask)
 
143
        task = bugtasks[0]
 
144
        url = canonical_url(task)
 
145
        recorder = QueryCollector()
 
146
        recorder.register()
 
147
        self.addCleanup(recorder.unregister)
 
148
        self.invalidate_caches(task)
 
149
        self.getUserBrowser(url, owner)
 
150
        # At least 20 of these should be removed.
 
151
        self.assertThat(recorder, HasQueryCount(LessThan(100)))
 
152
        count_with_no_branches = recorder.count
 
153
        self.invalidate_caches(task)
 
154
        with person_logged_in(owner):
 
155
            for sp in sourcepackages:
 
156
                target_branch = f.makePackageBranch(
 
157
                    sourcepackage=sp, owner=owner)
 
158
                source_branch = f.makeBranchTargetBranch(
 
159
                    target_branch.target, owner=owner)
 
160
                bug.linkBranch(source_branch, owner)
 
161
                f.makeBranchMergeProposal(
 
162
                    target_branch=target_branch,
 
163
                    registrant=owner,
 
164
                    source_branch=source_branch)
 
165
        self.getUserBrowser(url, owner)
 
166
        # Ideally this should be much fewer, but this tries to keep a win of
 
167
        # removing more than half of these.
 
168
        self.assertThat(recorder, HasQueryCount(
 
169
            LessThan(count_with_no_branches + 45),
 
170
            ))
 
171
 
127
172
    def test_interesting_activity(self):
128
173
        # The interesting_activity property returns a tuple of interesting
129
174
        # `BugActivityItem`s.