]> err.no Git - dak/commitdiff
prepare statements only once
authorMike O'Connor <stew@vireo.org>
Fri, 13 Mar 2009 16:04:22 +0000 (12:04 -0400)
committerMike O'Connor <stew@vireo.org>
Fri, 13 Mar 2009 16:04:22 +0000 (12:04 -0400)
Signed-off-by: Mike O'Connor <stew@vireo.org>
dak/contents.py
dak/process_unchecked.py
daklib/dbconn.py

index 9e3e35d32253d87fabdbb7e1892603f6a678fce6..d12440f1e56a6c4a0e4487bb3a2afd9f0a59de79 100644 (file)
@@ -242,9 +242,9 @@ class Contents(object):
         """
         cursor = DBConn().cursor();
         cursor.execute( "BEGIN WORK" )
-        cursor.execute( remove_pending_contents_cruft_q )
-        cursor.execute( remove_filename_cruft_q )
-        cursor.execute( remove_filepath_cruft_q )
+        DBConn().prepare("remove_pending_contents_cruft_q", remove_pending_contents_cruft_q)
+        DBConn().prepare("remove_filename_cruft_q", remove_filename_cruft_q)
+        DBConn().prepare("remove_filepath_cruft_q", remove_filepath_cruft_q)
         cursor.execute( "COMMIT" )
 
 
@@ -255,9 +255,9 @@ class Contents(object):
         pooldir = Config()[ 'Dir::Pool' ]
 
         cursor = DBConn().cursor();
-        cursor.execute( debs_q )
-        cursor.execute( olddeb_q )
-        cursor.execute( arches_q )
+        DBConn().prepare("debs_q",debs_q)
+        DBConn().prepare("olddeb_q",olddeb_q)
+        DBConn().prepare("arches_q",arches_q)
 
         suites = self._suites()
         for suite in [i.lower() for i in suites]:
@@ -292,9 +292,9 @@ class Contents(object):
         """
         cursor = DBConn().cursor();
 
-        cursor.execute( arches_q )
-        cursor.execute( contents_q )
-        cursor.execute( udeb_contents_q )
+        DBConn().prepare( "arches_q", arches_q )
+        DBConn().prepare( "contents_q", contents_q )
+        DBConn().prepare( "udeb_contents_q", udeb_contents_q )
 
         debtype_id=DBConn().get_override_type_id("deb")
         udebtype_id=DBConn().get_override_type_id("udeb")
index 8a49f009e5ffdff7931442c28e0182e31eb8db12..aa38a0032c5de584e63ff9a56b22236ca295b35e 100755 (executable)
@@ -389,7 +389,8 @@ def check_files():
     cursor = DBConn().cursor()
     # Check for packages that have moved from one component to another
     # STU: this should probably be changed to not join on architecture, suite tables but instead to used their cached name->id mappings from DBConn
-    cursor.execute("""PREPARE moved_pkg_q(text,text,text) AS
+    DBConn().prepare("moved_pkg_q", """
+        PREPARE moved_pkg_q(text,text,text) AS
         SELECT c.name FROM binaries b, bin_associations ba, suite s, location l,
                     component c, architecture a, files f
         WHERE b.package = $1 AND s.suite_name = $2
index 05bb208fd8ad163b92ca2b9c7a89994c5a183389..8b25d258d93958332882dd0a302e1dbe0295b276 100755 (executable)
@@ -113,6 +113,14 @@ class DBConn(Singleton):
                        'suite_version': Cache(lambda x: '%s_%s' % (x['source'], x['suite'])),
                       }
 
+        self.prepared_statements = {}
+
+    def prepare(self,name,statement):
+        if not self.prepared_statements.has_key(name):
+            c = self.cursor()
+            c.execute(statement)
+            self.prepared_statements[name] = statement
+
     def clear_caches(self):
         self.__init_caches()