aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-17 21:59:45 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-17 21:59:45 +0000
commite1af7c62ee26b33be9ced00561bda8873ada8fc6 (patch)
tree49b41d341b05fa10d0e3ea5a5c41ddc7d915fe95 /Source
parent5363acf332619a5fc823ff126363a0b030373f35 (diff)
downloadsequelpro-e1af7c62ee26b33be9ced00561bda8873ada8fc6.tar.gz
sequelpro-e1af7c62ee26b33be9ced00561bda8873ada8fc6.tar.bz2
sequelpro-e1af7c62ee26b33be9ced00561bda8873ada8fc6.zip
• some improvement to speed up queryString:
- caching of delegate && respondsToSelector - use clock() to calculate query's execution time • converting to cString: if utf8 encoding make usage of UTF8String • added to StringAddition to display µs for a timeIntervall
Diffstat (limited to 'Source')
-rw-r--r--Source/CMMCPConnection.h3
-rw-r--r--Source/CMMCPConnection.m27
-rw-r--r--Source/SPStringAdditions.m6
3 files changed, 26 insertions, 10 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h
index f69c3069..f0505956 100644
--- a/Source/CMMCPConnection.h
+++ b/Source/CMMCPConnection.h
@@ -72,6 +72,9 @@
NSDate *lastKeepAliveSuccess;
BOOL retryAllowed;
+
+ BOOL delegateResponseToWillQueryString;
+
}
- (id) init;
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
index 5d5cf52e..7dc8804f 100644
--- a/Source/CMMCPConnection.m
+++ b/Source/CMMCPConnection.m
@@ -261,6 +261,7 @@ static void forcePingTimeout(int signalNumber);
[self timeZone]; // Getting the timezone used by the server.
isMaxAllowedPacketEditable = [self isMaxAllowedPacketEditable];
+
if (![self fetchMaxAllowedPacket]) {
[self setLastErrorMessage:nil];
if (connectionTunnel) {
@@ -699,7 +700,7 @@ static void forcePingTimeout(int signalNumber);
- (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding
{
CMMCPResult *theResult = nil;
- NSDate *queryStartDate;
+ float queryStartTime;
const char *theCQuery;
unsigned long theCQueryLength;
int queryResultCode;
@@ -722,9 +723,11 @@ static void forcePingTimeout(int signalNumber);
}
[self stopKeepAliveTimer];
+
+ queryStartTime = clock();
// Inform the delegate about the query
- if (delegate && [delegate respondsToSelector:@selector(willQueryString:)]) {
+ if (delegateResponseToWillQueryString) {
[delegate willQueryString:query];
}
@@ -736,11 +739,11 @@ static void forcePingTimeout(int signalNumber);
// Check query length against max_allowed_packet; if it is larger, the
// query would error, so if max_allowed_packet is editable for the user
// increase it for the current session and reconnect.
- if([self getMaxAllowedPacket] < theCQueryLength) {
+ if(maxAllowedPacketSize < theCQueryLength) {
if(isMaxAllowedPacketEditable) {
- currentMaxAllowedPacket = [self getMaxAllowedPacket];
+ currentMaxAllowedPacket = maxAllowedPacketSize;
[self setMaxAllowedPacketTo:strlen(theCQuery)+1024 resetSize:NO];
[self reconnect];
@@ -748,7 +751,7 @@ static void forcePingTimeout(int signalNumber);
NSString *errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The query length of %d bytes is larger than max_allowed_packet size (%d).",
@"error message if max_allowed_packet < query size"),
- theCQueryLength, [self getMaxAllowedPacket]];
+ theCQueryLength, maxAllowedPacketSize];
// Write a log entry and update the connection error messages for those uses that check it
if ([delegate respondsToSelector:@selector(queryGaveError:)]) [delegate queryGaveError:errorMessage];
@@ -779,9 +782,8 @@ static void forcePingTimeout(int signalNumber);
// Run (or re-run) the query, timing the execution time of the query - note
// that this time will include network lag.
- queryStartDate = [NSDate date];
queryResultCode = mysql_real_query(mConnection, theCQuery, theCQueryLength);
- lastQueryExecutionTime = [[NSDate date] timeIntervalSinceDate:queryStartDate];
+ lastQueryExecutionTime = (clock() - queryStartTime)/CLOCKS_PER_SEC;
// On success, capture the results
if (0 == queryResultCode) {
@@ -929,6 +931,7 @@ static void forcePingTimeout(int signalNumber);
- (void)setDelegate:(id)object
{
delegate = object;
+ delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:@selector(willQueryString:)]);
}
/* Getting the currently used time zone (in communication with the DB server). */
@@ -1130,7 +1133,11 @@ static void forcePingTimeout(int signalNumber)
*/
- (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding
{
- NSMutableData *theData;
+
+ if(encoding == NSUTF8StringEncoding)
+ return [theString UTF8String];
+
+ NSMutableData *theData;
if (! theString) {
return (const char *)NULL;
@@ -1226,7 +1233,7 @@ static void forcePingTimeout(int signalNumber)
*/
- (int) setMaxAllowedPacketTo:(int)newSize resetSize:(BOOL)reset
{
- if(![self isMaxAllowedPacketEditable] || newSize < 1024) return [self getMaxAllowedPacket];
+ if(![self isMaxAllowedPacketEditable] || newSize < 1024) return maxAllowedPacketSize;
mysql_query(mConnection, [[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %d", newSize] UTF8String]);
// Inform the user via a log entry about that change according to reset value
@@ -1236,7 +1243,7 @@ static void forcePingTimeout(int signalNumber)
else
[delegate queryGaveError:[NSString stringWithFormat:@"Query too large; max_allowed_packet temporarily set to %d for the current session to allow query to succeed", newSize]];
- return [self getMaxAllowedPacket];
+ return maxAllowedPacketSize;
}
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index def9ce56..da4380ff 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -80,6 +80,12 @@
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
+ if (timeInterval < 0.001) {
+ timeInterval = (timeInterval * 1000000);
+ [numberFormatter setFormat:@"#,##0 µs"];
+
+ return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:timeInterval]];
+ }
if (timeInterval < 1) {
timeInterval = (timeInterval * 1000);
[numberFormatter setFormat:@"#,##0 ms"];