summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2019-02-06 20:36:01 +0000
committerMagnus Hagander2019-02-06 20:36:01 +0000
commite937795ea90ba1a1b72fed942ef385b285c3a378 (patch)
treefbe56f1fd9394db4f4d352562a9ad9b4ff6fc81c
parenta3bac5922db76efd5b6bb331a7141e9ca3209c4a (diff)
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..
-rw-r--r--pgcommitfest/commitfest/feeds.py12
-rw-r--r--pgcommitfest/commitfest/models.py2
-rw-r--r--pgcommitfest/commitfest/templates/activity.html2
-rw-r--r--pgcommitfest/commitfest/views.py8
4 files changed, 7 insertions, 17 deletions
diff --git a/pgcommitfest/commitfest/feeds.py b/pgcommitfest/commitfest/feeds.py
index 969de69..aa950fb 100644
--- a/pgcommitfest/commitfest/feeds.py
+++ b/pgcommitfest/commitfest/feeds.py
@@ -18,20 +18,14 @@ class ActivityFeed(Feed):
return self.activity
def item_title(self, item):
- if self.cfid:
- return item['name']
- else:
- return '{cfname}: {name}'.format(**item)
+ return item['name']
def item_description(self, item):
- if self.cfid:
- return "<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(**item)
- else:
- return "<div>Commitfest: {cfname}</div><div>Patch: {name}</div><div>User: {by}</div><div>{what}</div>".format(**item)
+ return "<div>Patch: {name}</div><div>User: {by}</div>\n<div>{what}</div>".format(**item)
def item_link(self, item):
if self.cfid:
- return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(cfid=self.cfid, **item)
+ return 'https://commitfest.postgresql.org/{0}/{1}/'.format(self.cfid, item['patchid'])
else:
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(**item)
diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py
index cb1c1dc..f061ff2 100644
--- a/pgcommitfest/commitfest/models.py
+++ b/pgcommitfest/commitfest/models.py
@@ -223,7 +223,7 @@ class PatchOnCommitFest(models.Model):
class PatchHistory(models.Model):
patch = models.ForeignKey(Patch, blank=False, null=False)
- date = models.DateTimeField(blank=False, null=False, auto_now_add=True)
+ date = models.DateTimeField(blank=False, null=False, auto_now_add=True, db_index=True)
by = models.ForeignKey(User, blank=False, null=False)
what = models.CharField(max_length=500, null=False, blank=False)
diff --git a/pgcommitfest/commitfest/templates/activity.html b/pgcommitfest/commitfest/templates/activity.html
index a864eee..1d5a060 100644
--- a/pgcommitfest/commitfest/templates/activity.html
+++ b/pgcommitfest/commitfest/templates/activity.html
@@ -7,7 +7,6 @@
<tr>
<th>Time</th>
<th>User</th>
-{%if not commitfest%}<th>CommitFest</th>{%endif%}
<th>Patch</th>
<th>Activity</th>
</tr>
@@ -17,7 +16,6 @@
<tr>
<td style="white-space: nowrap;">{{a.date}}</td>
<td>{{a.by}}</td>
-{%if not commitfest%}<td>{{a.cfname}}</td>{%endif%}
<td><a href="/{%if commitfest%}{{commitfest.id}}{%else%}{{a.cfid}}{%endif%}/{{a.patchid}}/">{{a.name}}</a></td>
<td>{{a.what}}</td>
</tr>
diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py
index 0c9591b..c52ff9c 100644
--- a/pgcommitfest/commitfest/views.py
+++ b/pgcommitfest/commitfest/views.py
@@ -56,14 +56,12 @@ def activity(request, cfid=None, rss=None):
# we're evil. And also because the number has been verified
# when looking up the cf itself, so nothing can be injected
# there.
- extrafields = ''
- where = 'WHERE poc.commitfest_id={0}'.format(cf.id)
+ where = 'WHERE EXISTS (SELECT 1 FROM commitfest_patchoncommitfest poc2 WHERE poc2.patch_id=p.id AND poc2.commitfest_id={0})'.format(cf.id)
else:
cf = None
- extrafields = ',poc.commitfest_id AS cfid,cf.name AS cfname'
- where = ' INNER JOIN commitfest_commitfest cf ON cf.id=poc.commitfest_id'
+ where = ''
- 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)
+ 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)
curs = connection.cursor()
curs.execute(sql)