Skip to content

Commit e937795

Browse files
committed
Fix activity feed queries
These clearly had little to do with reality since they would return duplicate entries if a patch was in more than one cf..
1 parent a3bac59 commit e937795

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

pgcommitfest/commitfest/feeds.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@ def items(self):
1818
return self.activity
1919

2020
def item_title(self, item):
21-
if self.cfid:
22-
return item['name']
23-
else:
24-
return '{cfname}: {name}'.format(**item)
21+
return item['name']
2522

2623
def item_description(self, item):
27-
if self.cfid:
28-
return "<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(**item)
29-
else:
30-
return "<div>Commitfest: {cfname}</div><div>Patch: {name}</div><div>User: {by}</div><div>{what}</div>".format(**item)
24+
return "<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(**item)
3125

3226
def item_link(self, item):
3327
if self.cfid:
34-
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(cfid=self.cfid, **item)
28+
return 'https://commitfest.postgresql.org/{0}/{1}/'.format(self.cfid, item['patchid'])
3529
else:
3630
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(**item)
3731

pgcommitfest/commitfest/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class Meta:
223223

224224
class PatchHistory(models.Model):
225225
patch = models.ForeignKey(Patch, blank=False, null=False)
226-
date = models.DateTimeField(blank=False, null=False, auto_now_add=True)
226+
date = models.DateTimeField(blank=False, null=False, auto_now_add=True, db_index=True)
227227
by = models.ForeignKey(User, blank=False, null=False)
228228
what = models.CharField(max_length=500, null=False, blank=False)
229229

pgcommitfest/commitfest/templates/activity.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<tr>
88
<th>Time</th>
99
<th>User</th>
10-
{%if not commitfest%}<th>CommitFest</th>{%endif%}
1110
<th>Patch</th>
1211
<th>Activity</th>
1312
</tr>
@@ -17,7 +16,6 @@
1716
<tr>
1817
<td style="white-space: nowrap;">{{a.date}}</td>
1918
<td>{{a.by}}</td>
20-
{%if not commitfest%}<td>{{a.cfname}}</td>{%endif%}
2119
<td><a href="/{%if commitfest%}{{commitfest.id}}{%else%}{{a.cfid}}{%endif%}/{{a.patchid}}/">{{a.name}}</a></td>
2220
<td>{{a.what}}</td>
2321
</tr>

pgcommitfest/commitfest/views.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ def activity(request, cfid=None, rss=None):
5656
# we're evil. And also because the number has been verified
5757
# when looking up the cf itself, so nothing can be injected
5858
# there.
59-
extrafields = ''
60-
where = 'WHERE poc.commitfest_id={0}'.format(cf.id)
59+
where = 'WHERE EXISTS (SELECT 1 FROM commitfest_patchoncommitfest poc2 WHERE poc2.patch_id=p.id AND poc2.commitfest_id={0})'.format(cf.id)
6160
else:
6261
cf = None
63-
extrafields = ',poc.commitfest_id AS cfid,cf.name AS cfname'
64-
where = ' INNER JOIN commitfest_commitfest cf ON cf.id=poc.commitfest_id'
62+
where = ''
6563

66-
sql = "SELECT ph.date, auth_user.username AS by, ph.what, p.id AS patchid, p.name{0} FROM commitfest_patchhistory ph INNER JOIN commitfest_patch p ON ph.patch_id=p.id INNER JOIN auth_user on auth_user.id=ph.by_id INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id=p.id {1} ORDER BY ph.date DESC LIMIT {2}".format(extrafields, where, num)
64+
sql = "SELECT ph.date, auth_user.username AS by, ph.what, p.id AS patchid, p.name, (SELECT max(commitfest_id) FROM commitfest_patchoncommitfest poc WHERE poc.patch_id=p.id) AS cfid FROM commitfest_patchhistory ph INNER JOIN commitfest_patch p ON ph.patch_id=p.id INNER JOIN auth_user on auth_user.id=ph.by_id {0} ORDER BY ph.date DESC LIMIT {1}".format(where, num)
6765

6866
curs = connection.cursor()
6967
curs.execute(sql)

0 commit comments

Comments
 (0)