[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.6/kdenetwork/kopete/plugins/statistics
From: Lamarque Souza <lamarque () gmail ! com>
Date: 2011-03-05 3:16:10
Message-ID: 20110305031610.6BE203E1F2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1223776 by lvsouza:
Backporting r1223427, statistics plugin: batch status updated on exit into a single transaction.
M +27 -0 statisticsdb.cpp
M +4 -0 statisticsdb.h
M +23 -0 statisticsplugin.cpp
M +2 -0 statisticsplugin.h
--- branches/KDE/4.6/kdenetwork/kopete/plugins/statistics/statisticsdb.cpp #1223775:1223776
@@ -16,6 +16,7 @@
*/
#include <QByteArray>
+#include <QSqlDriver>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
@@ -41,6 +42,8 @@
return;
}
+ has_transaction = m_db.driver()->hasFeature(QSqlDriver::Transactions);
+
// Creates the tables if they do not exist.
QStringList result = query ( "SELECT name FROM sqlite_master WHERE type='table'" );
@@ -134,3 +137,27 @@
return values;
}
+
+bool StatisticsDB::transaction()
+{
+ if (!has_transaction)
+ return true;
+
+ bool ret = m_db.transaction();
+ if (!ret)
+ kError ( 14315 ) << "failed to open transaction";
+
+ return ret;
+}
+
+bool StatisticsDB::commit()
+{
+ if (!has_transaction)
+ return true;
+
+ bool ret = m_db.commit();
+ if (!ret)
+ kError ( 14315 ) << "failed to commit transaction:" << m_db.lastError().text();
+
+ return ret;
+}
--- branches/KDE/4.6/kdenetwork/kopete/plugins/statistics/statisticsdb.h #1223775:1223776
@@ -29,8 +29,12 @@
//sql helper methods
QStringList query ( const QString& statement, QStringList* const names = 0, bool debug = false );
QString escapeString ( QString string );
+
+ bool transaction ();
+ bool commit ();
private:
QSqlDatabase m_db;
+ bool has_transaction;
};
#endif
--- branches/KDE/4.6/kdenetwork/kopete/plugins/statistics/statisticsplugin.cpp #1223775:1223776
@@ -284,4 +284,27 @@
return "";
}
+void StatisticsPlugin::aboutToUnload()
+{
+ /* Upon exit kopete will set the online status of each metacontact to
+ * "unknown", causing a storm of synchronous writes to the DB.
+ * Disconnect the signal and batch a single transaction.
+ */
+ m_db->transaction();
+
+ QMap<Kopete::MetaContact *, StatisticsContact *>::iterator it;
+ for (it = statisticsContactMap.begin(); it != statisticsContactMap.end(); ++it) {
+ Kopete::MetaContact *mc = it.key();
+ StatisticsContact *sc = it.value();
+
+ disconnect(mc, 0, this, 0);
+ sc->onlineStatusChanged(Kopete::OnlineStatus::Unknown);
+ }
+
+ m_db->commit();
+
+ /* Report ready for unload */
+ emit readyForUnload();
+}
+
#include "statisticsplugin.moc"
--- branches/KDE/4.6/kdenetwork/kopete/plugins/statistics/statisticsplugin.h #1223775:1223776
@@ -99,6 +99,8 @@
/// Method to access m_db member
StatisticsDB *db() { return m_db; }
+
+ void aboutToUnload();
private slots:
// Do the initializations
void slotInitialize();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic