Merge lp:~stevenk/launchpad/destroy-branchsparkview into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 13482
Proposed branch: lp:~stevenk/launchpad/destroy-branchsparkview
Merge into: lp:launchpad
Diff against target: 242 lines (+0/-175)
4 files modified
lib/lp/code/browser/branch.py (+0/-58)
lib/lp/code/browser/branchlisting.py (+0/-21)
lib/lp/code/browser/configure.zcml (+0/-7)
lib/lp/code/browser/tests/test_branch.py (+0/-89)
To merge this branch: bzr merge lp:~stevenk/launchpad/destroy-branchsparkview
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+68627@code.launchpad.net

Commit message

[r=wgrant][no-qa] Nuke BranchSparkView from orbit.

Description of the change

Nuke BranchSparkView from orbit.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

Destroy.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branch.py'
2--- lib/lp/code/browser/branch.py 2011-07-11 03:58:41 +0000
3+++ lib/lp/code/browser/branch.py 2011-07-21 02:44:36 +0000
4@@ -21,7 +21,6 @@
5 'BranchNavigation',
6 'BranchEditMenu',
7 'BranchInProductView',
8- 'BranchSparkView',
9 'BranchUpgradeView',
10 'BranchURL',
11 'BranchView',
12@@ -1463,60 +1462,3 @@
13 @property
14 def prefix(self):
15 return "tryagain"
16-
17-
18-class BranchSparkView(LaunchpadView):
19- """This view generates the JSON data for the commit sparklines."""
20-
21- __for__ = IBranch
22-
23- # How many days to look for commits.
24- COMMIT_DAYS = 90
25-
26- def _commitCounts(self):
27- """Return a dict of commit counts for rendering."""
28- epoch = (
29- datetime.now(
30- tz=pytz.UTC) - timedelta(days=(self.COMMIT_DAYS - 1)))
31- # Make a datetime for that date, but midnight.
32- epoch = epoch.replace(hour=0, minute=0, second=0, microsecond=0)
33- commits = dict(self.context.commitsForDays(epoch))
34- # However storm returns tz-unaware datetime objects.
35- day = datetime(year=epoch.year, month=epoch.month, day=epoch.day)
36- days = [day + timedelta(days=count)
37- for count in range(self.COMMIT_DAYS)]
38-
39- commit_list = []
40- total_commits = 0
41- most_commits = 0
42- for index, day in enumerate(days):
43- count = commits.get(day, 0)
44- commit_list.append(count)
45- total_commits += count
46- if count >= most_commits:
47- most_commits = count
48- max_index = index
49- return {'count': total_commits,
50- 'commits': commit_list,
51- 'max_commits': max_index}
52-
53- def render(self):
54- """Write out the commit data as a JSON string."""
55- # We want:
56- # count: total commit count
57- # last_commit: string to say when the last commit was
58- # commits: an array of COMMIT_DAYS values for commits for that day
59- # max_commits: an index into the commits array with the most commits,
60- # most recent wins any ties.
61- values = {'count': 0, 'max_commits': 0}
62- # Check there have been commits.
63- if self.context.revision_count == 0:
64- values['last_commit'] = 'empty branch'
65- else:
66- tip = self.context.getTipRevision()
67- adapter = queryAdapter(tip.revision_date, IPathAdapter, 'fmt')
68- values['last_commit'] = adapter.approximatedate()
69- values.update(self._commitCounts())
70-
71- self.request.response.setHeader('content-type', 'application/json')
72- return simplejson.dumps(values)
73
74=== modified file 'lib/lp/code/browser/branchlisting.py'
75--- lib/lp/code/browser/branchlisting.py 2011-07-01 14:42:52 +0000
76+++ lib/lp/code/browser/branchlisting.py 2011-07-21 02:44:36 +0000
77@@ -349,17 +349,6 @@
78 raise NotImplementedError(self.getBranchCollection)
79
80 @cachedproperty
81- def branch_sparks(self):
82- """Return a simplejson string for [id, url] for branch sparks."""
83- spark_lines = []
84- for count, branch in enumerate(self.visible_branches_for_view):
85- if self.view.showSparkLineForBranch(branch):
86- element_id = 'b-%s' % (count + 1)
87- element_url = canonical_url(branch, view_name='+spark')
88- spark_lines.append((element_id, element_url))
89- return simplejson.dumps(spark_lines)
90-
91- @cachedproperty
92 def _query_optimiser(self):
93 """Return the branch listing query optimiser utility."""
94 return getUtility(IBranchListingQueryOptimiser)
95@@ -599,11 +588,6 @@
96 # Separate the public property from the underlying virtual method.
97 return BranchListingBatchNavigator(self)
98
99- def showSparkLineForBranch(self, branch):
100- """Should the view render the code to generate the sparklines?"""
101- # Default to no for everything.
102- return False
103-
104 def getVisibleBranchesForUser(self):
105 """Get branches visible to the user.
106
107@@ -1161,11 +1145,6 @@
108 def _getCollection(self):
109 return getUtility(IAllBranches).inProduct(self.context)
110
111- def showSparkLineForBranch(self, branch):
112- """See `BranchListingView`."""
113- # Show the sparklines for the development focus branch only.
114- return branch == self.development_focus_branch
115-
116 @cachedproperty
117 def development_focus_branch(self):
118 dev_focus_branch = self.context.development_focus.branch
119
120=== modified file 'lib/lp/code/browser/configure.zcml'
121--- lib/lp/code/browser/configure.zcml 2011-06-28 11:10:51 +0000
122+++ lib/lp/code/browser/configure.zcml 2011-07-21 02:44:36 +0000
123@@ -657,13 +657,6 @@
124 class="lp.code.browser.branchvisibilitypolicy.RemoveBranchVisibilityTeamPolicyView"
125 permission="launchpad.Commercial"
126 template="../../app/templates/generic-edit.pt"/>
127- <browser:page
128- name="+spark"
129- for="lp.code.interfaces.branch.IBranch"
130- layer="lp.code.publisher.CodeLayer"
131- class="lp.code.browser.branch.BranchSparkView"
132- facet="branches"
133- permission="zope.Public"/>
134 <browser:menus
135 classes="
136 BranchContextMenu
137
138=== modified file 'lib/lp/code/browser/tests/test_branch.py'
139--- lib/lp/code/browser/tests/test_branch.py 2011-05-16 03:46:33 +0000
140+++ lib/lp/code/browser/tests/test_branch.py 2011-07-21 02:44:36 +0000
141@@ -38,7 +38,6 @@
142 BranchAddView,
143 BranchMirrorStatusView,
144 BranchReviewerEditView,
145- BranchSparkView,
146 BranchView,
147 )
148 from lp.code.browser.branchlisting import PersonOwnedBranchesView
149@@ -668,94 +667,6 @@
150 self.assertEqual("lp://dev/fooix", decorated_branch.bzr_identity)
151
152
153-class TestBranchSparkView(TestCaseWithFactory):
154- """Tests for the BranchSparkView class."""
155-
156- layer = DatabaseFunctionalLayer
157-
158- def test_empty_branch(self):
159- # A branch with no commits produces...
160- branch = self.factory.makeAnyBranch()
161- view = BranchSparkView(branch, LaunchpadTestRequest())
162- json = simplejson.loads(view.render())
163- self.assertEqual(0, json['count'])
164- self.assertEqual('empty branch', json['last_commit'])
165-
166- def test_content_type(self):
167- # The response has the correct (JSON) content type...
168- branch = self.factory.makeAnyBranch()
169- request = LaunchpadTestRequest()
170- view = BranchSparkView(branch, request)
171- view.render()
172- self.assertEqual(
173- request.response.getHeader('content-type'),
174- 'application/json')
175-
176- def test_old_commits(self):
177- # A branch with a commit older than the COMMIT_DAYS will create a list
178- # of commits that all say zero.
179- branch = self.factory.makeAnyBranch()
180- revision = self.factory.makeRevision(
181- revision_date=datetime(
182- year=2008, month=9, day=10, tzinfo=pytz.UTC))
183- branch.createBranchRevision(1, revision)
184- branch.updateScannedDetails(revision, 1)
185-
186- view = BranchSparkView(branch, LaunchpadTestRequest())
187- json = simplejson.loads(view.render())
188-
189- self.assertEqual(0, json['count'])
190- self.assertEqual([0] * 90, json['commits'])
191- self.assertEqual('2008-09-10', json['last_commit'])
192-
193- def test_last_commit_string(self):
194- # If the last commit was very recent, we get a nicer string.
195- branch = self.factory.makeAnyBranch()
196- # Make the revision date six hours ago.
197- revision_date = datetime.now(tz=pytz.UTC) - timedelta(seconds=6*3600)
198- revision = self.factory.makeRevision(
199- revision_date=revision_date)
200- branch.createBranchRevision(1, revision)
201- branch.updateScannedDetails(revision, 1)
202-
203- view = BranchSparkView(branch, LaunchpadTestRequest())
204- json = simplejson.loads(view.render())
205- self.assertEqual('6 hours ago', json['last_commit'])
206-
207- def test_new_commits(self):
208- # If there are no commits for the day, there are zeros, if there are
209- # commits, then the array contains the number of commits for that day.
210- branch = self.factory.makeAnyBranch()
211- # Create a commit 5 days ago.
212- revision_date = datetime.now(tz=pytz.UTC) - timedelta(days=5)
213- revision = self.factory.makeRevision(revision_date=revision_date)
214- branch.createBranchRevision(1, revision)
215- branch.updateScannedDetails(revision, 1)
216-
217- view = BranchSparkView(branch, LaunchpadTestRequest())
218- json = simplejson.loads(view.render())
219-
220- self.assertEqual(1, json['count'])
221- commits = ([0] * 84) + [1, 0, 0, 0, 0, 0]
222- self.assertEqual(commits, json['commits'])
223- self.assertEqual(84, json['max_commits'])
224-
225- def test_commit_for_just_now(self):
226- # A commit now should show as a commit on the last day.
227- branch = self.factory.makeAnyBranch()
228- revision_date = datetime.now(tz=pytz.UTC)
229- revision = self.factory.makeRevision(revision_date=revision_date)
230- branch.createBranchRevision(1, revision)
231- branch.updateScannedDetails(revision, 1)
232-
233- view = BranchSparkView(branch, LaunchpadTestRequest())
234- json = simplejson.loads(view.render())
235-
236- self.assertEqual(1, json['count'])
237- commits = ([0] * 89) + [1]
238- self.assertEqual(commits, json['commits'])
239-
240-
241 class TestBranchProposalsVisible(TestCaseWithFactory):
242 """Test that the BranchView filters out proposals the user cannot see."""
243