[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] prepare statements only once



Signed-off-by: Mike O'Connor <stew@vireo.org>
---
 dak/contents.py          |   18 +++++++++---------
 dak/process_unchecked.py |    3 ++-
 daklib/dbconn.py         |    8 ++++++++
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/dak/contents.py b/dak/contents.py
index 9e3e35d..d12440f 100644
--- a/dak/contents.py
+++ b/dak/contents.py
@@ -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")
diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py
index 8a49f00..aa38a00 100755
--- a/dak/process_unchecked.py
+++ b/dak/process_unchecked.py
@@ -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
diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index 05bb208..8b25d25 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -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()
 
-- 
1.5.6.5



Reply to: