From 974049dd4fbe6b42c1a8349f72ea355cf6a38634 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Fri, 16 Oct 2009 19:36:36 +0000 Subject: - Improve on r1423 by avoiding stringWithFormat: within the query construction loop, enormously reducing memory usage in big loops - Use 64k chunks instead of 256k chunks - seems to give *much* better performance, possibly due to MySQL parsing/cache sizes (?) - When restoring the query console to allow updates again after a loop, trigger a refresh of the view if the console is visible --- Source/SPQueryController.h | 4 +++- Source/SPQueryController.m | 9 ++++++++- Source/TableContent.m | 25 +++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index 8a350a32..d030014a 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -58,7 +58,6 @@ } @property (readwrite, retain) NSFont *consoleFont; -@property (readwrite) BOOL allowConsoleUpdate; + (SPQueryController *)sharedQueryController; @@ -72,6 +71,9 @@ - (void)updateEntries; +- (BOOL) allowConsoleUpdate; +- (void) setAllowConsoleUpdate:(BOOL)allowUpdate; + - (void)showMessageInConsole:(NSString *)message; - (void)showErrorInConsole:(NSString *)error; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index 25b972bb..c1e632d1 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -54,7 +54,6 @@ static SPQueryController *sharedQueryController = nil; @implementation SPQueryController @synthesize consoleFont; -@synthesize allowConsoleUpdate; /* * Returns the shared query console. @@ -403,6 +402,14 @@ static SPQueryController *sharedQueryController = nil; return [[self window] validateMenuItem:menuItem]; } +- (BOOL) allowConsoleUpdate { + return allowConsoleUpdate; +} +- (void) setAllowConsoleUpdate:(BOOL)allowUpdate { + allowConsoleUpdate = allowUpdate; + if (allowUpdate && [[self window] isVisible]) [self updateEntries]; +} + - (void)updateEntries { [consoleTableView reloadData]; diff --git a/Source/TableContent.m b/Source/TableContent.m index 734b4d96..19f77db4 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -1869,21 +1869,26 @@ [deleteQuery appendString:@"("]; for(NSString *primaryKeyFieldName in primaryKeyFieldNames) { - [deleteQuery appendFormat:@"%@=", [primaryKeyFieldName backtickQuotedString]]; id keyValue = [NSArrayObjectAtIndex(tableValues, index) objectAtIndex:[[[tableDataInstance columnWithName:primaryKeyFieldName] objectForKey:@"datacolumnindex"] intValue]]; - if([keyValue isKindOfClass:[NSData class]]) - [deleteQuery appendString:[NSString stringWithFormat:@"X'%@'", [mySQLConnection prepareBinaryData:keyValue]]]; - else - [deleteQuery appendString:[NSString stringWithFormat:@"'%@'", [keyValue description]]]; - - [deleteQuery appendString:@" AND "]; + [deleteQuery appendString:[primaryKeyFieldName backtickQuotedString]]; + if ([keyValue isKindOfClass:[NSData class]]) { + [deleteQuery appendString:@"=X'"]; + [deleteQuery appendString:[mySQLConnection prepareBinaryData:keyValue]]; + } else { + [deleteQuery appendString:@"='"]; + [deleteQuery appendString:[mySQLConnection prepareString:[keyValue description]]]; + } + [deleteQuery appendString:@"' AND "]; } - [deleteQuery setString:[NSString stringWithFormat:@"%@)", [deleteQuery substringToIndex:([deleteQuery length]-5)]]]; + + // Remove the trailing AND and add the closing bracket + [deleteQuery deleteCharactersInRange:NSMakeRange([deleteQuery length]-5, 5)]; + [deleteQuery appendString:@")"]; - // Split deletion query into 256k chunks - if([deleteQuery length] > 256000) { + // Split deletion query into 64k chunks + if([deleteQuery length] > 64000) { [mySQLConnection queryString:deleteQuery]; // Remember affected rows for error checking affectedRows += [mySQLConnection affectedRows]; -- cgit v1.2.3