glom r1811 - in trunk: . glom/libglom
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1811 - in trunk: . glom/libglom
- Date: Tue, 16 Dec 2008 10:18:14 +0000 (UTC)
Author: murrayc
Date: Tue Dec 16 10:18:13 2008
New Revision: 1811
URL: http://svn.gnome.org/viewvc/glom?rev=1811&view=rev
Log:
2008-12-16 Murray Cumming <murrayc murrayc com>
* glom/libglom/connectionpool.cc: connect(): Store a cache of the
connection for 30 seconds, to avoid unnecessary reconnects. Clear the
cache when setting the username/password/database, to force a reconnect.
Modified:
trunk/ChangeLog
trunk/glom/libglom/connectionpool.cc
Modified: trunk/glom/libglom/connectionpool.cc
==============================================================================
--- trunk/glom/libglom/connectionpool.cc (original)
+++ trunk/glom/libglom/connectionpool.cc Tue Dec 16 10:18:13 2008
@@ -307,6 +307,8 @@
return m_backend.get();
}
+
+
//static:
#ifdef GLIBMM_EXCEPTIONS_ENABLED
sharedptr<SharedConnection> ConnectionPool::get_and_connect()
@@ -329,6 +331,25 @@
return result;
}
+
+
+// Store the connection for a few seconds in case it
+// is immediately requested again, to avoid making a new connection
+// and introspecting again, which is slow.
+static sharedptr<SharedConnection> connection_cached;
+static sigc::connection connection_cached_timeout_connection;
+
+bool on_connection_pool_cache_timeout()
+{
+ //std::cout << "DEBUG: Clearing connection cache." << std::endl;
+
+ //Forget the cached connection after a few seconds:
+ connection_cached.clear();
+
+ return false; //Don't call this again.
+}
+
+
#ifdef GLIBMM_EXCEPTIONS_ENABLED
sharedptr<SharedConnection> ConnectionPool::connect()
#else
@@ -348,8 +369,19 @@
//Remember that somebody is using it:
m_sharedconnection_refcount++;
+ //Store the connection in a cache for a few seconds to avoid unnecessary disconnections/reconnections:
+ //std::cout << "DEBUG: Stored connection cache." << std::endl;
+ connection_cached = sharedConnection;
+ connection_cached_timeout_connection.disconnect(); //Stop the existing timeout if it has not run yet.
+ connection_cached_timeout_connection = Glib::signal_timeout().connect_seconds(&on_connection_pool_cache_timeout, 30 /* seconds */);
+
return sharedConnection;
}
+ else if(connection_cached)
+ {
+ //Avoid a reconnection immediately after disconnecting:
+ return connection_cached;
+ }
else
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -368,7 +400,9 @@
else
{
//Allow get_meta_store_data() to succeed:
+ std::cout << "DEBUG: Calling update_meta_store() ..." << std::endl;
m_refGdaConnection->update_meta_store();
+ std::cout << "DEBUG: ... update_meta_store() has finished." << std::endl;
// Connection succeeded
// Create the fieldtypes member if it has not already been done:
@@ -431,16 +465,25 @@
}
m_user = value;
+
+ //Make sure that connect() makes a new connection:
+ connection_cached.clear();
}
void ConnectionPool::set_password(const Glib::ustring& value)
{
m_password = value;
+
+ //Make sure that connect() makes a new connection:
+ connection_cached.clear();
}
void ConnectionPool::set_database(const Glib::ustring& value)
{
m_database = value;
+
+ //Make sure that connect() makes a new connection:
+ connection_cached.clear();
}
Glib::ustring ConnectionPool::get_user() const
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]