aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-08-20 23:34:21 +0000
committerrowanbeentje <rowan@beent.je>2009-08-20 23:34:21 +0000
commitb3c737fa485e28a81cc3de8b076fa40aa083fb37 (patch)
treeb858eb09a8620dcadc61ede416c42806e6c8a30d /Source
parente25c021cf7473c033e65d2472f25913aaff44c50 (diff)
downloadsequelpro-b3c737fa485e28a81cc3de8b076fa40aa083fb37.tar.gz
sequelpro-b3c737fa485e28a81cc3de8b076fa40aa083fb37.tar.bz2
sequelpro-b3c737fa485e28a81cc3de8b076fa40aa083fb37.zip
Experimental change to make table content browsing much faster:
- Use the new MCPStreamingResult in TableContent, replacing the old standard query/fetchResultAsArray. This appears to be much faster (and lower memory use) but I've left the old fetchResultAsArray in place for the time being until we see how we feel about it.
Diffstat (limited to 'Source')
-rw-r--r--Source/TableContent.m41
1 files changed, 39 insertions, 2 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 7b458947..0a0acedc 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -382,6 +382,15 @@
NSString *queryStringBeforeLimit = nil;
NSString *filterString;
MCPResult *queryResult;
+ MCPStreamingResult *streamingResult;
+ NSArray *tempRow;
+ NSMutableArray *modifiedRow = [NSMutableArray array];
+ NSMutableArray *columnBlobStatuses = [NSMutableArray array];
+ int i;
+ Class nullClass = [NSNull class];
+ id prefsNullValue = [prefs objectForKey:@"NullValue"];
+ BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"];
+ long columnsCount = [dataColumns count];
// Notify any listeners that a query has started
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
@@ -425,8 +434,36 @@
[self setUsedQuery:queryString];
// Run the query and capture the result
- queryResult = [mySQLConnection queryString:queryString];
- [tableValues setArray:[self fetchResultAsArray:queryResult]];
+
+ // Build up an array of which columns are blobs for faster iteration
+ for ( i = 0; i < columnsCount ; i++ ) {
+ [columnBlobStatuses addObject:[NSNumber numberWithBool:[tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"] ]]];
+ }
+
+ [tableValues removeAllObjects];
+ streamingResult = [mySQLConnection streamingQueryString:queryString];
+ while (tempRow = [streamingResult fetchNextRowAsArray]) {
+ [modifiedRow removeAllObjects];
+ for ( i = 0; i < columnsCount; i++ ) {
+ if ( [NSArrayObjectAtIndex(tempRow, i) isMemberOfClass:nullClass] ) {
+ [modifiedRow addObject:prefsNullValue];
+ } else {
+ [modifiedRow addObject:NSArrayObjectAtIndex(tempRow, i)];
+ }
+ }
+
+ // Add values for hidden blob and text fields if appropriate
+ if ( prefsLoadBlobsAsNeeded ) {
+ for ( i = 0 ; i < columnsCount ; i++ ) {
+ if ( [NSArrayObjectAtIndex(columnBlobStatuses, i) boolValue] ) {
+ [modifiedRow replaceObjectAtIndex:i withObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")];
+ }
+ }
+ }
+
+ [tableValues addObject:[NSMutableArray arrayWithArray:modifiedRow]];
+ }
+ [streamingResult release];
// If the result is empty, and a limit is active, reset the limit
if ([prefs boolForKey:@"LimitResults"] && queryStringBeforeLimit && ![tableValues count]) {