From b3c737fa485e28a81cc3de8b076fa40aa083fb37 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 20 Aug 2009 23:34:21 +0000 Subject: 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. --- Source/TableContent.m | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'Source') 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]) { -- cgit v1.2.3