changeset 186:8da56d2a70d6

Enormously speed up activity view.
author Daniele Nicolodi <daniele@grinta.net>
date Tue, 08 Nov 2011 12:46:54 +0100
parents 5e2d298e01ef
children e06b0e162757
files src/ltpdarepo/views/browse.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/views/browse.py	Tue Nov 08 12:22:38 2011 +0100
+++ b/src/ltpdarepo/views/browse.py	Tue Nov 08 12:46:54 2011 +0100
@@ -679,8 +679,10 @@
         # collect number of objects for each interval
         curs.execute("""SELECT ts.begin AS date, COUNT(objmeta.obj_id) AS count
                         FROM timeintervals AS ts
-                        LEFT OUTER JOIN `%s`.objmeta ON (objmeta.submitted BETWEEN ts.begin AND ts.end)
-                        GROUP BY ts.begin, ts.end""" % database)
+                        LEFT OUTER JOIN (SELECT obj_id, submitted FROM `%s`.objmeta
+                                          WHERE submitted > %%s AND submitted < %%s) AS objmeta
+                                     ON (objmeta.submitted BETWEEN ts.begin AND ts.end)
+                        GROUP BY ts.begin, ts.end""" % database, (begin, end + dt))
 
         activity = curs.fetchall()