Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. === modified file 'lib/lp/code/browser/branch.py'
  2. --- lib/lp/code/browser/branch.py 2011-02-17 03:29:50 +0000
  3. +++ lib/lp/code/browser/branch.py 2011-02-25 02:46:55 +0000
  4. @@ -339,10 +339,7 @@
  5. return Link('+register-merge', text, icon='add', enabled=enabled)
  6.  
  7. def link_bug(self):
  8. - if self.context.linked_bugs:
  9. - text = 'Link to another bug report'
  10. - else:
  11. - text = 'Link to a bug report'
  12. + text = 'Link a bug report'
  13. return Link('+linkbug', text, icon='add')
  14.  
  15. def link_blueprint(self):
  16. @@ -604,12 +601,11 @@
  17. @cachedproperty
  18. def linked_bugs(self):
  19. """Return a list of DecoratedBugs linked to the branch."""
  20. - bugs = self.context.linked_bugs
  21. if self.context.is_series_branch:
  22. - bugs = [
  23. - bug for bug in bugs
  24. - if bug.bugtask.status in UNRESOLVED_BUGTASK_STATUSES]
  25. - return bugs
  26. + status_filter = UNRESOLVED_BUGTASK_STATUSES
  27. + else:
  28. + status_filter = None
  29. + return list(self.context.getLinkedBugsAndTasks(status_filter)
  30.  
  31. @cachedproperty
  32. def revision_info(self):
  33.  
  34. === modified file 'lib/lp/code/browser/decorations.py'
  35. --- lib/lp/code/browser/decorations.py 2010-08-24 10:45:57 +0000
  36. +++ lib/lp/code/browser/decorations.py 2011-02-25 02:50:42 +0000
  37. @@ -100,6 +100,8 @@
  38. tasks, we get them all at once, and provide decorated bugs (that have
  39. their tasks cached).
  40. """
  41. + # To whomever it may concern, this function should be pushed down to
  42. + # the model, and the related visibility checks made part of the query.
  43. bugs = defaultdict(list)
  44. for bug, task in self.branch.getLinkedBugsAndTasks():
  45. bugs[bug].append(task)
  46.  
  47. === modified file 'lib/lp/code/browser/tests/test_branch.py'
  48. --- lib/lp/code/browser/tests/test_branch.py 2011-02-25 02:08:52 +0000
  49. +++ lib/lp/code/browser/tests/test_branch.py 2011-02-25 02:38:32 +0000
  50. @@ -19,6 +19,7 @@
  51. from canonical.config import config
  52. from canonical.database.constants import UTC_NOW
  53. from canonical.launchpad.helpers import truncate_text
  54. +from canonical.launchpad.webapp.publisher import canonical_url
  55. from canonical.launchpad.webapp.servers import LaunchpadTestRequest
  56. from canonical.testing.layers import (
  57. DatabaseFunctionalLayer,
  58. @@ -29,8 +30,6 @@
  59. find_tag_by_id,
  60. setupBrowser,
  61. )
  62. -from canonical.launchpad.webapp.publisher import canonical_url
  63. -
  64. from lp.app.interfaces.headings import IRootContext
  65. from lp.bugs.interfaces.bugtask import (
  66. BugTaskStatus,
  67. @@ -58,6 +57,7 @@
  68. person_logged_in,
  69. TestCaseWithFactory,
  70. )
  71. +from lp.testing.matchers import BrowsesWithQueryLimit
  72. from lp.testing.views import create_initialized_view
  73.  
  74.  
  75. @@ -361,6 +361,41 @@
  76. self.assertTrue(
  77. bug.bugtask.status in UNRESOLVED_BUGTASK_STATUSES)
  78.  
  79. + def test_linked_bugs_nonseries_branch_query_scaling(self):
  80. + # As we add linked bugs, the query count for a branch index page stays
  81. + # constant.
  82. + branch = self.factory.makeAnyBranch()
  83. + browses_under_limit = BrowsesWithQueryLimit(54, branch.owner)
  84. + # Start with some bugs, otherwise we might see a spurious increase
  85. + # depending on optimisations in eager loaders.
  86. + with person_logged_in(branch.owner):
  87. + self._addBugLinks(branch)
  88. + self.assertThat(branch, browses_under_limit)
  89. + with person_logged_in(branch.owner):
  90. + # Add plenty of bugs.
  91. + for _ in range(5):
  92. + self._addBugLinks(branch)
  93. + self.assertThat(branch, browses_under_limit)
  94. +
  95. + def test_linked_bugs_series_branch_query_scaling(self):
  96. + # As we add linked bugs, the query count for a branch index page stays
  97. + # constant.
  98. + product = self.factory.makeProduct()
  99. + branch = self.factory.makeProductBranch(product=product)
  100. + browses_under_limit = BrowsesWithQueryLimit(54, branch.owner)
  101. + with person_logged_in(product.owner):
  102. + product.development_focus.branch = branch
  103. + # Start with some bugs, otherwise we might see a spurious increase
  104. + # depending on optimisations in eager loaders.
  105. + with person_logged_in(branch.owner):
  106. + self._addBugLinks(branch)
  107. + self.assertThat(branch, browses_under_limit)
  108. + with person_logged_in(branch.owner):
  109. + # Add plenty of bugs.
  110. + for _ in range(5):
  111. + self._addBugLinks(branch)
  112. + self.assertThat(branch, browses_under_limit)
  113. +
  114. def _add_revisions(self, branch, nr_revisions=1):
  115. revisions = []
  116. for seq in range(1, nr_revisions+1):
  117.  
  118. === modified file 'lib/lp/code/interfaces/branch.py'
  119. --- lib/lp/code/interfaces/branch.py 2011-02-04 16:34:12 +0000
  120. +++ lib/lp/code/interfaces/branch.py 2011-02-25 02:44:09 +0000
  121. @@ -409,8 +409,12 @@
  122. readonly=True,
  123. value_type=Reference(schema=Interface))) # Really IBug
  124.  
  125. - def getLinkedBugsAndTasks():
  126. - """Return a result set for the bugs with their tasks."""
  127. + def getLinkedBugsAndTasks(status_filter):
  128. + """Return a result set for the bugs with their tasks.
  129. +
  130. + :param status_filter: If none, return all linked bugs. For any other
  131. + value, passed onto the bug search as a constraint.
  132. + """
  133.  
  134. @call_with(registrant=REQUEST_USER)
  135. @operation_parameters(
  136.  
  137. === modified file 'lib/lp/code/model/branch.py'
  138. --- lib/lp/code/model/branch.py 2011-01-25 18:59:18 +0000
  139. +++ lib/lp/code/model/branch.py 2011-02-25 02:44:20 +0000
  140. @@ -302,8 +302,8 @@
  141. 'Bug', joinColumn='branch', otherColumn='bug',
  142. intermediateTable='BugBranch', orderBy='id')
  143.  
  144. - def getLinkedBugsAndTasks(self):
  145. - """Return a result set for the bugs with their tasks."""
  146. + def getLinkedBugsAndTasks(self, status_filter):
  147. + """See `IBranch`."""
  148. from lp.bugs.model.bug import Bug
  149. from lp.bugs.model.bugbranch import BugBranch
  150. from lp.bugs.model.bugtask import BugTask
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement