Author: justi9
Date: 2010-06-14 17:51:43 -0400 (Mon, 14 Jun 2010)
New Revision: 4026
Modified:
mgmt/newdata/mint/python/mint/update.py
Log:
Combine multiple sql operations into one cursor execute call
Modified: mgmt/newdata/mint/python/mint/update.py
===================================================================
--- mgmt/newdata/mint/python/mint/update.py 2010-06-14 19:58:24 UTC (rev 4025)
+++ mgmt/newdata/mint/python/mint/update.py 2010-06-14 21:51:43 UTC (rev 4026)
@@ -207,44 +207,66 @@
self.process_properties(obj, object_columns)
self.process_statistics(obj, object_columns, sample_columns)
+ statements = list()
+
if object_columns:
object_columns.append(cls.sql_table._qmf_update_time)
- new = obj._sync_time is None
+ if obj._sync_time:
+ sql = cls.sql_update.emit(object_columns)
+ stats.updated += 1
+ else:
+ sql = cls.sql_insert.emit(object_columns)
+ stats.created += 1
- obj.save(cursor, object_columns)
+ statements.append(sql)
- if new:
- stats.created += 1
- else:
- stats.updated += 1
-
if sample_columns:
- drop = False
+ keep = True
if stats.enqueued - stats.dequeued > 100:
# There's some pressure, so consider dropping samples
now = datetime.now()
-
+
if update_time < now - minutes_ago:
# The sample is too old
- drop = True
+ keep = False
if last_update_time and last_update_time > now - seconds_ago:
# The samples are too fidelitous
- drop = True
+ keep = False
- if drop:
+ if keep:
+ sample_columns.append(cls.sql_samples_table._qmf_update_time)
+
+ sql = cls.sql_samples_insert.emit(sample_columns)
+ stats.sampled += 1
+
+ statements.append(sql)
+ else:
stats.dropped += 1
- else:
- col = cls.sql_samples_table._qmf_update_time
- sample_columns.append(col)
- obj.add_sample(cursor, sample_columns)
+ if statements:
+ text = "; ".join(statements)
- stats.sampled += 1
+ try:
+ cursor.execute(text, obj.__dict__)
+ except:
+ log.exception("%s failed", self)
+ log.info("Sql text: %s", text)
+ log.info("Sql values:")
+
+ for item in sorted(obj.__dict__.items()):
+ log.info(" %-34s %r", *item)
+
+ log.info("Sql row count: %i", cursor.rowcount)
+
+ raise
+
+ obj._sync_time = datetime.now()
+
def get_class(self):
class_key = self.object.getClassKey()
Show replies by date