From b54a768bc63b01475a79426ea519d22217a001c5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 18 Jun 2009 08:18:33 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20tiny=20improvements=20to=20speed=20u?= =?UTF-8?q?p=20queryString:=20-=20cache=20the=20function=20pointer=20for?= =?UTF-8?q?=20delegate=20willPerformQuery:=20-=20if=20Console=20Log=20wind?= =?UTF-8?q?ow=20is=20NOT=20visible=20suppress=20reloadData=20and=20scrolli?= =?UTF-8?q?ng=20to=20last=20line=20(this=20speeds=20it=20up=20remarkably);?= =?UTF-8?q?=20if=20user=20opens=20the=20Console=20log=20window=20it=20will?= =?UTF-8?q?=20be=20synchronized=20-=20timeIntervall=20for=20execution=20ti?= =?UTF-8?q?me=20will=20be=20divide=20by=20CLOCKS=5FPER=5FSEC=20in=20[NSStr?= =?UTF-8?q?ing=20stringForTimeInterval]=20-=20removed=20for=20utf8=20enc?= =?UTF-8?q?=20in=20cString=20the=20return=20UTF8String=20(no=20significant?= =?UTF-8?q?=20difference)=20=E2=80=A2=20now=20execution=20time=20shows=20o?= =?UTF-8?q?nly=20the=20time=20for=20mysql=5Freal=5Fquery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMMCPConnection.h | 4 +++- Source/CMMCPConnection.m | 34 ++++++++++++++++------------------ Source/CustomQuery.m | 8 ++++---- Source/SPQueryConsole.h | 2 ++ Source/SPQueryConsole.m | 14 +++++++++++--- Source/SPStringAdditions.h | 2 +- Source/SPStringAdditions.m | 7 +++++-- Source/TableDocument.m | 8 +++++++- 8 files changed, 49 insertions(+), 30 deletions(-) (limited to 'Source') diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index f0505956..6d0b0811 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -59,7 +59,7 @@ BOOL useKeepAlive; float keepAliveInterval; - float lastQueryExecutionTime; + int lastQueryExecutionTime; NSString *lastQueryErrorMessage; unsigned int lastQueryErrorId; my_ulonglong lastQueryAffectedRows; @@ -75,6 +75,8 @@ BOOL delegateResponseToWillQueryString; + IMP willQueryStringPtr; + } - (id) init; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 7dc8804f..68056ba1 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -664,15 +664,6 @@ static void forcePingTimeout(int signalNumber); } -/* - * Override the standard queryString: method to default to the connection encoding, as before, - * before pssing on to queryString: usingEncoding:. - */ -- (CMMCPResult *)queryString:(NSString *) query -{ - return [self queryString:query usingEncoding:mEncoding]; -} - /* * Via that method the current mySQLConnection will be informed * which object sent the current query. @@ -690,6 +681,15 @@ static void forcePingTimeout(int signalNumber); } +/* + * Override the standard queryString: method to default to the connection encoding, as before, + * before pssing on to queryString: usingEncoding:. + */ +- (CMMCPResult *)queryString:(NSString *) query +{ + return [self queryString:query usingEncoding:mEncoding]; +} + /* * Modified version of queryString to be used in Sequel Pro. @@ -700,7 +700,7 @@ static void forcePingTimeout(int signalNumber); - (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding { CMMCPResult *theResult = nil; - float queryStartTime; + int queryStartTime; const char *theCQuery; unsigned long theCQueryLength; int queryResultCode; @@ -724,12 +724,11 @@ static void forcePingTimeout(int signalNumber); [self stopKeepAliveTimer]; - queryStartTime = clock(); + // queryStartTime = clock(); // Inform the delegate about the query - if (delegateResponseToWillQueryString) { - [delegate willQueryString:query]; - } + if (delegateResponseToWillQueryString) + (void)(NSString*)(*willQueryStringPtr)(delegate, @selector(willQueryString:), query); // Derive the query string in the correct encoding theCQuery = [self cStringFromString:query usingEncoding:encoding]; @@ -782,8 +781,9 @@ 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. + queryStartTime = clock(); queryResultCode = mysql_real_query(mConnection, theCQuery, theCQueryLength); - lastQueryExecutionTime = (clock() - queryStartTime)/CLOCKS_PER_SEC; + lastQueryExecutionTime = (clock() - queryStartTime); // On success, capture the results if (0 == queryResultCode) { @@ -932,6 +932,7 @@ static void forcePingTimeout(int signalNumber); { delegate = object; delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:@selector(willQueryString:)]); + willQueryStringPtr = [delegate methodForSelector:@selector(willQueryString:)]; } /* Getting the currently used time zone (in communication with the DB server). */ @@ -1134,9 +1135,6 @@ static void forcePingTimeout(int signalNumber) - (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding { - if(encoding == NSUTF8StringEncoding) - return [theString UTF8String]; - NSMutableData *theData; if (! theString) { diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 495f6b20..b59fe084 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -585,26 +585,26 @@ if (totalAffectedRows==1) { [affectedRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"1 row affected in total, by %i queries taking %@", @"text showing one row has been affected by multiple queries"), totalQueriesRun, - [NSString stringForTimeInterval:executionTime] + [NSString stringForTimeInterval:executionTime intervalInClocks:YES] ]]; } else { [affectedRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%i rows affected in total, by %i queries taking %@", @"text showing how many rows have been affected by multiple queries"), totalAffectedRows, totalQueriesRun, - [NSString stringForTimeInterval:executionTime] + [NSString stringForTimeInterval:executionTime intervalInClocks:YES] ]]; } } else { if (totalAffectedRows==1) { [affectedRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"1 row affected, taking %@", @"text showing one row has been affected by a single query"), - [NSString stringForTimeInterval:executionTime] + [NSString stringForTimeInterval:executionTime intervalInClocks:YES] ]]; } else { [affectedRowsText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%i rows affected, taking %@", @"text showing how many rows have been affected by a single query"), totalAffectedRows, - [NSString stringForTimeInterval:executionTime] + [NSString stringForTimeInterval:executionTime intervalInClocks:YES] ]]; } diff --git a/Source/SPQueryConsole.h b/Source/SPQueryConsole.h index 281f2d2e..85ea7cbe 100644 --- a/Source/SPQueryConsole.h +++ b/Source/SPQueryConsole.h @@ -40,6 +40,7 @@ BOOL showSelectStatementsAreDisabled; BOOL showHelpStatementsAreDisabled; BOOL filterIsActive; + NSMutableString *activeFilterString; } @@ -54,6 +55,7 @@ - (IBAction)toggleShowSelectShowStatements:(id)sender; - (IBAction)toggleShowHelpStatements:(id)sender; +- (void)updateEntries; - (void)showMessageInConsole:(NSString *)message; - (void)showErrorInConsole:(NSString *)error; diff --git a/Source/SPQueryConsole.m b/Source/SPQueryConsole.m index a7c7263d..dab9a9a0 100644 --- a/Source/SPQueryConsole.m +++ b/Source/SPQueryConsole.m @@ -365,6 +365,12 @@ static SPQueryConsole *sharedQueryConsole = nil; return [[self window] validateMenuItem:menuItem]; } +- (void)updateEntries +{ + [consoleTableView reloadData]; + [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; +} + /** * Standard dealloc. */ @@ -494,9 +500,11 @@ static SPQueryConsole *sharedQueryConsole = nil; [clearConsoleButton setEnabled:YES]; } - // Reload the table and scroll to the new message - [consoleTableView reloadData]; - [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; + // Reload the table and scroll to the new message if it's visible (for speed) + if ( [[self window] isVisible] ) { + [consoleTableView reloadData]; + [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; + } } /** diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 8e50bbd4..318e8d4d 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -28,7 +28,7 @@ @interface NSString (SPStringAdditions) + (NSString *)stringForByteSize:(int)byteSize; -+ (NSString *)stringForTimeInterval:(float)timeInterval; ++ (NSString *)stringForTimeInterval:(float)timeInterval intervalInClocks:(BOOL)inClocks; - (NSString *)backtickQuotedString; - (NSArray *)lineRangesForRange:(NSRange)aRange; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index da4380ff..4b74e905 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -74,10 +74,13 @@ // // Returns a human readable version string of the supplied time interval. // ------------------------------------------------------------------------------- -+ (NSString *)stringForTimeInterval:(float)timeInterval ++ (NSString *)stringForTimeInterval:(float)timeInterval intervalInClocks:(BOOL)inClocks { NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; - + + if(inClocks) + timeInterval = timeInterval/CLOCKS_PER_SEC; + [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; if (timeInterval < 0.001) { diff --git a/Source/TableDocument.m b/Source/TableDocument.m index e638ffd9..270ebe5b 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -985,7 +985,13 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum - (void)toggleConsole:(id)sender { BOOL isConsoleVisible = [[[SPQueryConsole sharedQueryConsole] window] isVisible]; - + + // If the Console window is not visible data are not reloaded (for speed). + // Due to that update list if user opens the Console window. + if(!isConsoleVisible) { + [[SPQueryConsole sharedQueryConsole] updateEntries]; + } + // Show or hide the console [[[SPQueryConsole sharedQueryConsole] window] setIsVisible:(!isConsoleVisible)]; -- cgit v1.2.3