Reviewers: ,


Please review this at http://codereview.tryton.org/624002/

Affected files:
  M trytond/backend/postgresql/database.py


Index: trytond/backend/postgresql/database.py
===================================================================

--- a/trytond/backend/postgresql/database.py
+++ b/trytond/backend/postgresql/database.py
@@ -24,6 +24,7 @@

 RE_FROM = re.compile('.* from "?([a-zA-Z_0-9]+)"?.*$')
 RE_INTO = re.compile('.* into "?([a-zA-Z_0-9]+)"?.*$')
+RE_UPDATE = re.compile('update "?([a-zA-Z_0-9]+)"?.*$')
 RE_VERSION = re.compile(r'\S+ (\d+)\.(\d+)')


@@ -280,9 +281,11 @@
         self.commit()
         self.sql_from_log = {}
         self.sql_into_log = {}
+        self.sql_update_log = {}
         self.count = {
             'from': 0,
             'into': 0,
+            'update': 0,
         }

     @property
@@ -323,6 +326,11 @@
                 self.sql_into_log[res_into.group(1)][0] += 1
self.sql_into_log[res_into.group(1)][1] += time.time() - now
                 self.count['into'] += 1
+            res_update = RE_UPDATE.match(sql.lower())
+            if res_update:
+                self.sql_update_log.setdefault(res_update.group(1), [0, 0])
+                self.sql_update_log[res_update.group(1)][0] += 1
+ self.sql_update_log[res_update.group(1)][1] += time.time() - now
         return res

     def _print_log(self, sql_type='from'):
@@ -330,6 +338,8 @@
         logger.info("SQL LOG %s:" % (sql_type,))
         if sql_type == 'from':
             logs = self.sql_from_log.items()
+        elif sql_type == 'update':
+            logs = self.sql_update_log.items()
         else:
             logs = self.sql_into_log.items()
         logs.sort(lambda x, y: cmp(x[1][1], y[1][1]))
@@ -343,6 +353,7 @@
         if self.sql_log:
             self._print_log('from')
             self._print_log('into')
+            self._print_log('update')
         self.cursor.close()

# This force the cursor to be freed, and thus, available again. It is



--
--
[email protected] mailing list



Reply via email to