Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === modified file 'lib/lp/code/browser/branch.py'
- --- lib/lp/code/browser/branch.py 2011-02-17 03:29:50 +0000
- +++ lib/lp/code/browser/branch.py 2011-02-25 02:46:55 +0000
- @@ -339,10 +339,7 @@
- return Link('+register-merge', text, icon='add', enabled=enabled)
- def link_bug(self):
- - if self.context.linked_bugs:
- - text = 'Link to another bug report'
- - else:
- - text = 'Link to a bug report'
- + text = 'Link a bug report'
- return Link('+linkbug', text, icon='add')
- def link_blueprint(self):
- @@ -604,12 +601,11 @@
- @cachedproperty
- def linked_bugs(self):
- """Return a list of DecoratedBugs linked to the branch."""
- - bugs = self.context.linked_bugs
- if self.context.is_series_branch:
- - bugs = [
- - bug for bug in bugs
- - if bug.bugtask.status in UNRESOLVED_BUGTASK_STATUSES]
- - return bugs
- + status_filter = UNRESOLVED_BUGTASK_STATUSES
- + else:
- + status_filter = None
- + return list(self.context.getLinkedBugsAndTasks(status_filter)
- @cachedproperty
- def revision_info(self):
- === modified file 'lib/lp/code/browser/decorations.py'
- --- lib/lp/code/browser/decorations.py 2010-08-24 10:45:57 +0000
- +++ lib/lp/code/browser/decorations.py 2011-02-25 02:50:42 +0000
- @@ -100,6 +100,8 @@
- tasks, we get them all at once, and provide decorated bugs (that have
- their tasks cached).
- """
- + # To whomever it may concern, this function should be pushed down to
- + # the model, and the related visibility checks made part of the query.
- bugs = defaultdict(list)
- for bug, task in self.branch.getLinkedBugsAndTasks():
- bugs[bug].append(task)
- === modified file 'lib/lp/code/browser/tests/test_branch.py'
- --- lib/lp/code/browser/tests/test_branch.py 2011-02-25 02:08:52 +0000
- +++ lib/lp/code/browser/tests/test_branch.py 2011-02-25 02:38:32 +0000
- @@ -19,6 +19,7 @@
- from canonical.config import config
- from canonical.database.constants import UTC_NOW
- from canonical.launchpad.helpers import truncate_text
- +from canonical.launchpad.webapp.publisher import canonical_url
- from canonical.launchpad.webapp.servers import LaunchpadTestRequest
- from canonical.testing.layers import (
- DatabaseFunctionalLayer,
- @@ -29,8 +30,6 @@
- find_tag_by_id,
- setupBrowser,
- )
- -from canonical.launchpad.webapp.publisher import canonical_url
- -
- from lp.app.interfaces.headings import IRootContext
- from lp.bugs.interfaces.bugtask import (
- BugTaskStatus,
- @@ -58,6 +57,7 @@
- person_logged_in,
- TestCaseWithFactory,
- )
- +from lp.testing.matchers import BrowsesWithQueryLimit
- from lp.testing.views import create_initialized_view
- @@ -361,6 +361,41 @@
- self.assertTrue(
- bug.bugtask.status in UNRESOLVED_BUGTASK_STATUSES)
- + def test_linked_bugs_nonseries_branch_query_scaling(self):
- + # As we add linked bugs, the query count for a branch index page stays
- + # constant.
- + branch = self.factory.makeAnyBranch()
- + browses_under_limit = BrowsesWithQueryLimit(54, branch.owner)
- + # Start with some bugs, otherwise we might see a spurious increase
- + # depending on optimisations in eager loaders.
- + with person_logged_in(branch.owner):
- + self._addBugLinks(branch)
- + self.assertThat(branch, browses_under_limit)
- + with person_logged_in(branch.owner):
- + # Add plenty of bugs.
- + for _ in range(5):
- + self._addBugLinks(branch)
- + self.assertThat(branch, browses_under_limit)
- +
- + def test_linked_bugs_series_branch_query_scaling(self):
- + # As we add linked bugs, the query count for a branch index page stays
- + # constant.
- + product = self.factory.makeProduct()
- + branch = self.factory.makeProductBranch(product=product)
- + browses_under_limit = BrowsesWithQueryLimit(54, branch.owner)
- + with person_logged_in(product.owner):
- + product.development_focus.branch = branch
- + # Start with some bugs, otherwise we might see a spurious increase
- + # depending on optimisations in eager loaders.
- + with person_logged_in(branch.owner):
- + self._addBugLinks(branch)
- + self.assertThat(branch, browses_under_limit)
- + with person_logged_in(branch.owner):
- + # Add plenty of bugs.
- + for _ in range(5):
- + self._addBugLinks(branch)
- + self.assertThat(branch, browses_under_limit)
- +
- def _add_revisions(self, branch, nr_revisions=1):
- revisions = []
- for seq in range(1, nr_revisions+1):
- === modified file 'lib/lp/code/interfaces/branch.py'
- --- lib/lp/code/interfaces/branch.py 2011-02-04 16:34:12 +0000
- +++ lib/lp/code/interfaces/branch.py 2011-02-25 02:44:09 +0000
- @@ -409,8 +409,12 @@
- readonly=True,
- value_type=Reference(schema=Interface))) # Really IBug
- - def getLinkedBugsAndTasks():
- - """Return a result set for the bugs with their tasks."""
- + def getLinkedBugsAndTasks(status_filter):
- + """Return a result set for the bugs with their tasks.
- +
- + :param status_filter: If none, return all linked bugs. For any other
- + value, passed onto the bug search as a constraint.
- + """
- @call_with(registrant=REQUEST_USER)
- @operation_parameters(
- === modified file 'lib/lp/code/model/branch.py'
- --- lib/lp/code/model/branch.py 2011-01-25 18:59:18 +0000
- +++ lib/lp/code/model/branch.py 2011-02-25 02:44:20 +0000
- @@ -302,8 +302,8 @@
- 'Bug', joinColumn='branch', otherColumn='bug',
- intermediateTable='BugBranch', orderBy='id')
- - def getLinkedBugsAndTasks(self):
- - """Return a result set for the bugs with their tasks."""
- + def getLinkedBugsAndTasks(self, status_filter):
- + """See `IBranch`."""
- from lp.bugs.model.bug import Bug
- from lp.bugs.model.bugbranch import BugBranch
- from lp.bugs.model.bugtask import BugTask
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement