Fix activity feed queries
authorMagnus Hagander <magnus@hagander.net>
Wed, 6 Feb 2019 20:36:01 +0000 (21:36 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 6 Feb 2019 20:36:01 +0000 (21:36 +0100)
These clearly had little to do with reality since they would return
duplicate entries if a patch was in more than one cf..

pgcommitfest/commitfest/feeds.py
pgcommitfest/commitfest/models.py
pgcommitfest/commitfest/templates/activity.html
pgcommitfest/commitfest/views.py

index 969de699faad5b7772aa9bc8be36dd3643b05def..aa950fb3a825bba54c87f0709f847b6b5c6c433a 100644 (file)
@@ -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)
 
index cb1c1dc786765f5fb5d1ea15c659647c64fd76a3..f061ff268c105ef369f5120a4f1620293e319a99 100644 (file)
@@ -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)
 
index a864eee88bf28963f69f3050641756f5b142a4f3..1d5a060f4e64b6b9a29978431189c6b1cbdf7de3 100644 (file)
@@ -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>
index 0c9591bd67e5ff53c9d17f0bc9585baf2b79651b..c52ff9c2bd722a1a5ce17aa19646b08f3b57b21a 100644 (file)
@@ -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)