changeset 17:b63f74313bab

Add an index for 'submitted' column in 'objmeta' table. To speed up activity view, add an index for 'submitted' column in 'objmeta' table during 2.5 to 2.6 database schema upgrade step.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 27 Jun 2011 14:07:08 +0200
parents 23bfe8ed4163
children 4c08f51482a3
files src/ltpdarepo/upgrade.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/upgrade.py	Mon Jun 27 14:05:38 2011 +0200
+++ b/src/ltpdarepo/upgrade.py	Mon Jun 27 14:07:08 2011 +0200
@@ -92,9 +92,15 @@
 def upgrade_25_to_26(conn):
     curs = conn.cursor()
 
-    # crerate queries table
-    curs.execute("""CREATE TABLE queries (name TEXT,
-                                          db TEXT,
-                                          querystring TEXT)""");    
-    
+    # crerate "queries" table
+    curs.execute("""CREATE TABLE IF NOT EXISTS
+                    queries (name TEXT, db TEXT, querystring TEXT)""")
+
+    # for each registered database
+    curs.execute("SELECT db_name FROM available_dbs")
+    databases = [row[0] for row in curs.fetchall()]
+    for db in databases:
+        # add index on "submitted" column to speed up activity view
+        curs.execute("""ALTER TABLE `%s`.objmeta ADD INDEX (submitted)""" % db)
+
     conn.commit()