aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2017-03-09 03:39:29 +0100
committerMax <post@wickenrode.com>2017-03-09 03:39:29 +0100
commit7c56b11d8bdead768e86643a4b61e3f293820330 (patch)
tree413e33bb2f9ab97d5e71532585447a7fb928d836 /Frameworks
parent6c3ab14a0cb89e64256c1d3e7db57adb3d45057c (diff)
downloadsequelpro-7c56b11d8bdead768e86643a4b61e3f293820330.tar.gz
sequelpro-7c56b11d8bdead768e86643a4b61e3f293820330.tar.bz2
sequelpro-7c56b11d8bdead768e86643a4b61e3f293820330.zip
* Turn `-[SPMySQLConnection checkConnectionIfNecessary]` into a public method, since it is actually the preferable way to `-[SPMySQLConnection checkConnection]` (which forces network IO in a new thread each time)
* Change `-[SPDatabaseStructure queryDbStructureWithUserInfo:]` doing a forced connection check inside a tight loop (#2306)
Diffstat (limited to 'Frameworks')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h1
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m4
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m4
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h1
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m60
5 files changed, 36 insertions, 34 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h b/Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h
index 99daca77..8fdf4e7e 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h
@@ -47,7 +47,6 @@
- (void)_disconnect;
- (void)_updateConnectionVariables;
- (void)_restoreConnectionVariables;
-- (BOOL)_checkConnectionIfNecessary;
- (void)_validateThreadSetup;
+ (void)_removeThreadVariables:(NSNotification *)aNotification;
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
index d96ebe52..594756be 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
@@ -79,7 +79,7 @@
// Ensure per-thread variables are set up
[self _validateThreadSetup];
- if (![self _checkConnectionIfNecessary]) return nil;
+ if (![self checkConnectionIfNecessary]) return nil;
// Perform a lossy conversion to bytes, using NSData to do the hard work. Preserves
// nul characters correctly.
@@ -259,7 +259,7 @@
[self _validateThreadSetup];
// Check the connection if necessary, returning nil if the state couldn't be validated
- if (![self _checkConnectionIfNecessary]) return nil;
+ if (![self checkConnectionIfNecessary]) return nil;
// Determine whether a maximum query size needs to be restored from a previous query
if (queryActionShouldRestoreMaxQuerySize != NSNotFound) {
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
index db846929..d8d87931 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
@@ -107,7 +107,7 @@
if (state != SPMySQLConnected) return nil;
// Check the connection if appropriate
- if (![self _checkConnectionIfNecessary]) return nil;
+ if (![self checkConnectionIfNecessary]) return nil;
// Lock the connection before using it
[self _lockConnection];
@@ -153,7 +153,7 @@
- (BOOL)serverShutdown
{
- if([self _checkConnectionIfNecessary]) {
+ if([self checkConnectionIfNecessary]) {
[self _lockConnection];
// Ensure per-thread variables are set up
[self _validateThreadSetup];
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
index 15b809f1..343d0d36 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
@@ -188,6 +188,7 @@
- (BOOL)isConnected;
- (BOOL)isConnectedViaSSL;
- (BOOL)checkConnection;
+- (BOOL)checkConnectionIfNecessary;
- (double)timeConnected;
- (BOOL)userTriggeredDisconnect;
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
index ce980af8..e8692895 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
@@ -336,6 +336,8 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
*
* WARNING: This method may return NO if the current thread is cancelled!
* You MUST check the isCancelled flag before using the result!
+ *
+ * NOTE: In general -checkConnectionIfNecessary should be used instead!
*/
- (BOOL)checkConnection
{
@@ -375,6 +377,35 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
}
/**
+ * If thirty seconds have passed since the last time the connection was
+ * used, check the connection.
+ * This minimises the impact of continuous additional connection checks -
+ * each of which requires a round trip to the server - but handles most
+ * network issues.
+ * Returns whether the connection is considered still valid.
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
+ */
+- (BOOL)checkConnectionIfNecessary
+{
+
+ // If the connection has been dropped in the background, trigger a
+ // reconnect and return the success state here
+ if (state == SPMySQLConnectionLostInBackground) {
+ return [self _reconnectAllowingRetries:YES];
+ }
+
+ // If the connection was recently used, return success
+ if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 30) {
+ return YES;
+ }
+
+ // Otherwise check the connection
+ return [self checkConnection];
+}
+
+/**
* Retrieve the time elapsed since the connection was established, in seconds.
* This time is retrieved in a monotonically increasing fashion and is high
* precision; it is used internally for query timing, and is reset on reconnections.
@@ -1043,35 +1074,6 @@ static uint64_t _elapsedMicroSecondsSinceAbsoluteTime(uint64_t comparisonTime)
}
/**
- * If thirty seconds have passed since the last time the connection was
- * used, check the connection.
- * This minimises the impact of continuous additional connection checks -
- * each of which requires a round trip to the server - but handles most
- * network issues.
- * Returns whether the connection is considered still valid.
- *
- * WARNING: This method may return NO if the current thread is cancelled!
- * You MUST check the isCancelled flag before using the result!
- */
-- (BOOL)_checkConnectionIfNecessary
-{
-
- // If the connection has been dropped in the background, trigger a
- // reconnect and return the success state here
- if (state == SPMySQLConnectionLostInBackground) {
- return [self _reconnectAllowingRetries:YES];
- }
-
- // If the connection was recently used, return success
- if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 30) {
- return YES;
- }
-
- // Otherwise check the connection
- return [self checkConnection];
-}
-
-/**
* Ensure that the thread this method is called on has been registered for
* use with MySQL. MySQL requires thread-specific variables for safe
* execution.