summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCătălin Badea <catalin.badea392@gmail.com>2012-08-19 20:11:14 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-19 20:11:14 (GMT)
commitfcabcf3bbd6d389900baaf20b33d75eca36d3808 (patch)
treeaf627ebaac0292350061f8bdf472bebc8f2d0144
parent7a46b1ddf4193c2f4ca789ef86b099f9d70842f9 (diff)
downloadswift-contrib-fcabcf3bbd6d389900baaf20b33d75eca36d3808.zip
swift-contrib-fcabcf3bbd6d389900baaf20b33d75eca36d3808.tar.bz2
Use async database access.
-rw-r--r--Swiften/History/SQLiteHistoryStorage.cpp16
-rw-r--r--Swiften/History/SQLiteHistoryStorage.h3
2 files changed, 18 insertions, 1 deletions
diff --git a/Swiften/History/SQLiteHistoryStorage.cpp b/Swiften/History/SQLiteHistoryStorage.cpp
index 5e3148b..ed0d6a3 100644
--- a/Swiften/History/SQLiteHistoryStorage.cpp
+++ b/Swiften/History/SQLiteHistoryStorage.cpp
@@ -8,6 +8,7 @@
#include <boost/lexical_cast.hpp>
#include <sqlite3.h>
+#include <3rdParty/SQLite/sqlite3async.h>
#include <Swiften/History/SQLiteHistoryStorage.h>
#include <boost/date_time/gregorian/gregorian.hpp>
@@ -25,7 +26,14 @@ inline std::string getEscapedString(const std::string& s) {
namespace Swift {
SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) {
- sqlite3_open(file.c_str(), &db_);
+ sqlite3_vfs vfs;
+
+ sqlite3async_initialize(NULL, true);
+ sqlite3_vfs_register(&vfs, false);
+
+ thread_ = new boost::thread(boost::bind(&SQLiteHistoryStorage::run, this));
+
+ sqlite3_open_v2(file.c_str(), &db_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "sqlite3async");
if (!db_) {
std::cerr << "Error opening database " << file << std::endl;
}
@@ -45,7 +53,9 @@ SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) {
}
SQLiteHistoryStorage::~SQLiteHistoryStorage() {
+ sqlite3async_shutdown();
sqlite3_close(db_);
+ delete thread_;
}
void SQLiteHistoryStorage::addMessage(const HistoryMessage& message) {
@@ -371,4 +381,8 @@ boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID
return boost::posix_time::ptime(boost::posix_time::not_a_date_time);
}
+void SQLiteHistoryStorage::run() {
+ sqlite3async_run();
+}
+
}
diff --git a/Swiften/History/SQLiteHistoryStorage.h b/Swiften/History/SQLiteHistoryStorage.h
index aae6db8..782334a 100644
--- a/Swiften/History/SQLiteHistoryStorage.h
+++ b/Swiften/History/SQLiteHistoryStorage.h
@@ -9,6 +9,7 @@
#include <boost/optional.hpp>
#include <Swiften/History/HistoryStorage.h>
+#include <boost/thread.hpp>
struct sqlite3;
@@ -26,6 +27,7 @@ namespace Swift {
boost::posix_time::ptime getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const;
private:
+ void run();
boost::gregorian::date getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const;
int getIDForJID(const JID&);
int addJID(const JID&);
@@ -34,5 +36,6 @@ namespace Swift {
boost::optional<int> getIDFromJID(const JID& jid) const;
sqlite3* db_;
+ boost::thread* thread_;
};
}