aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-30 09:10:02 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-30 09:10:02 +0000
commit5fd7c0a6c1f284a261d8e3cabe97db8601e2bd93 (patch)
tree5751ab514cf46a60676246b8ec5f748a88c61cf4
parent2424d968ad5e6d9516b15fead3edf26d0183c450 (diff)
downloadsequelpro-5fd7c0a6c1f284a261d8e3cabe97db8601e2bd93.tar.gz
sequelpro-5fd7c0a6c1f284a261d8e3cabe97db8601e2bd93.tar.bz2
sequelpro-5fd7c0a6c1f284a261d8e3cabe97db8601e2bd93.zip
• some speed improvements and code simplifications for navigator
• avoid making the completion key list unique since it's possible to insert unique items only • added trigger to query db structure after SQL import • some work to avoid http://log.sequelpro.com/view/90 (not yet ideally - WIP)
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m22
-rw-r--r--Source/CMTextView.m9
-rw-r--r--Source/SPNavigatorController.h2
-rw-r--r--Source/SPNavigatorController.m66
-rw-r--r--Source/TableDump.m3
-rw-r--r--Source/TableSource.m4
6 files changed, 53 insertions, 53 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 26f1a9b4..35d07a39 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -2055,6 +2055,8 @@ void performThreadedKeepAlive(void *ptr)
;
}
+ [allKeysofDbStructure addObject:db_id];
+
// Query all tables
for(NSString* table in tables) {
NSString *query = [NSString stringWithFormat:@"SHOW FULL COLUMNS FROM `%@` FROM `%@`",
@@ -2068,7 +2070,11 @@ void performThreadedKeepAlive(void *ptr)
continue;
}
theResult = mysql_use_result(structConnection);
+
NSString *table_id = [NSString stringWithFormat:@"%@%@%@", db_id, SPUniqueSchemaDelimiter, table];
+
+ [allKeysofDbStructure addObject:table_id];
+
while(row = mysql_fetch_row(theResult)) {
NSString *field = [self stringWithUTF8CString:row[0]];
NSString *type = [self stringWithUTF8CString:row[1]];
@@ -2083,8 +2089,6 @@ void performThreadedKeepAlive(void *ptr)
NSArray *a = [coll componentsSeparatedByString:@"_"];
charset = ([a count]) ? [a objectAtIndex:0] : @"";
- [allKeysofDbStructure addObject:db_id];
- [allKeysofDbStructure addObject:table_id];
[allKeysofDbStructure addObject:field_id];
if(![[structure valueForKey:connectionID] valueForKey:db_id] || [[[structure valueForKey:connectionID] valueForKey:db_id] isKindOfClass:[NSString class]] )
@@ -2112,8 +2116,12 @@ void performThreadedKeepAlive(void *ptr)
// NSLog(@"error %@", table);
continue;
}
+
theResult = mysql_use_result(structConnection);
NSString *table_id = [NSString stringWithFormat:@"%@%@%@", db_id, SPUniqueSchemaDelimiter, table];
+
+ [allKeysofDbStructure addObject:table_id];
+
NSString *charset;
while(row = mysql_fetch_row(theResult)) {
NSString *field = [self stringWithUTF8CString:row[0]];
@@ -2129,8 +2137,6 @@ void performThreadedKeepAlive(void *ptr)
NSArray *a = [coll componentsSeparatedByString:@"_"];
charset = ([a count]) ? [a objectAtIndex:0] : @"";
- [allKeysofDbStructure addObject:db_id];
- [allKeysofDbStructure addObject:table_id];
[allKeysofDbStructure addObject:field_id];
if(![[structure valueForKey:connectionID] valueForKey:db_id] || [[[structure valueForKey:connectionID] valueForKey:db_id] isKindOfClass:[NSString class]] )
@@ -2167,7 +2173,6 @@ void performThreadedKeepAlive(void *ptr)
NSString *security_type = [self stringWithUTF8CString:row[14]];
NSString *definer = [self stringWithUTF8CString:row[19]];
- [allKeysofDbStructure addObject:db_id];
[allKeysofDbStructure addObject:table_id];
[allKeysofDbStructure addObject:field_id];
@@ -2208,7 +2213,7 @@ void performThreadedKeepAlive(void *ptr)
*/
- (NSDictionary *)getDbStructure
{
- return [NSDictionary dictionaryWithDictionary:structure];
+ return [structure copy];
}
/**
@@ -2216,10 +2221,7 @@ void performThreadedKeepAlive(void *ptr)
*/
- (NSArray *)getAllKeysOfDbStructure
{
- if(allKeysofDbStructure && [allKeysofDbStructure count]) {
- return [NSArray arrayWithArray:allKeysofDbStructure];
- }
- return [NSArray array];
+ return [allKeysofDbStructure copy];
}
#pragma mark -
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index a4bcda58..2b9879b6 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -314,13 +314,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if(dbs != nil && [dbs isKindOfClass:[NSDictionary class]] && [dbs count]) {
NSMutableArray *allDbs = [NSMutableArray array];
- [allDbs addObjectsFromArray:[dbs allKeys]];
-
- // Add database names having no tables since they don't appear in the information_schema
- if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"] != nil)
- for(id db in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"])
- if(![allDbs containsObject:[NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, db]])
- [allDbs addObject:[NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, db]];
+ @try { [allDbs addObjectsFromArray:[dbs allKeys]]; }
+ @catch(id ae) { ; }
NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES selector:@selector(localizedCompare:)];
NSMutableArray *sortedDbs = [NSMutableArray array];
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h
index e92d5d26..2c6c88b9 100644
--- a/Source/SPNavigatorController.h
+++ b/Source/SPNavigatorController.h
@@ -55,6 +55,8 @@
NSRect selectionViewPort2;
BOOL ignoreUpdate;
BOOL isFiltered;
+
+ Class NSDictionaryClass;
}
+ (SPNavigatorController *)sharedNavigatorController;
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index abf709b8..5edb172b 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -76,7 +76,8 @@ static SPNavigatorController *sharedNavigatorController = nil;
ignoreUpdate = NO;
isFiltered = NO;
[syncButton setState:NSOffState];
-
+ NSDictionaryClass = [NSDictionary class];
+
}
return self;
@@ -181,7 +182,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
selection = [outlineSchema1 selectedItem];
if(selection) {
id parentObject = [outlineSchema1 parentForItem:selection] ? [outlineSchema1 parentForItem:selection] : schemaData;
- if(!parentObject || ![parentObject isKindOfClass:[NSDictionary class]] || ![parentObject objectForKey:selection]) return;
+ if(!parentObject || ![parentObject isKindOfClass:NSDictionaryClass] || ![parentObject objectForKey:selection]) return;
id parentKeys = [parentObject allKeysForObject:selection];
if(parentKeys && [parentKeys count] == 1)
selectedKey1 = [[parentKeys objectAtIndex:0] description];
@@ -195,7 +196,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
selection = [outlineSchema2 selectedItem];
if(selection) {
id parentObject = [outlineSchema2 parentForItem:selection] ? [outlineSchema2 parentForItem:selection] : schemaData;
- if(!parentObject || ![parentObject isKindOfClass:[NSDictionary class]] || ![parentObject objectForKey:selection]) return;
+ if(!parentObject || ![parentObject isKindOfClass:NSDictionaryClass] || ![parentObject objectForKey:selection]) return;
id parentKeys = [parentObject allKeysForObject:selection];
if(parentKeys && [parentKeys count] == 1)
selectedKey2 = [[parentKeys objectAtIndex:0] description];
@@ -220,7 +221,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
[outlineSchema2 collapseItem:[item objectForKey:[pathArray objectAtIndex:0]] collapseChildren:YES];
for(NSInteger i=0; i < [pathArray count]; i++) {
[aKey appendString:[pathArray objectAtIndex:i]];
- if(!item || ![item isKindOfClass:[NSDictionary class]] || ![item objectForKey:aKey]) break;
+ if(!item || ![item isKindOfClass:NSDictionaryClass] || ![item objectForKey:aKey]) break;
item = [item objectForKey:aKey];
[outlineSchema2 expandItem:item];
[aKey appendString:SPUniqueSchemaDelimiter];
@@ -234,7 +235,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
id item = [outlineSchema2 selectedItem];
// Try to scroll the view that all children of schemaPath are visible if possible
NSInteger cnt = 1;
- if([item isKindOfClass:[NSDictionary class]] || [item isKindOfClass:[NSArray class]])
+ if([item isKindOfClass:NSDictionaryClass] || [item isKindOfClass:[NSArray class]])
cnt = [item count]+1;
NSRange r = [outlineSchema2 rowsInRect:[outlineSchema2 visibleRect]];
NSInteger offset = (cnt > r.length) ? (r.length-2) : cnt;
@@ -436,12 +437,13 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
}
id structureData = [theConnection getDbStructure];
- if(structureData && [structureData objectForKey:connectionName] && [[structureData objectForKey:connectionName] isKindOfClass:[NSDictionary class]]) {
+ if(structureData && [structureData objectForKey:connectionName] && [[structureData objectForKey:connectionName] isKindOfClass:NSDictionaryClass]) {
for(id item in [[structureData objectForKey:connectionName] allKeys])
[[schemaData objectForKey:connectionName] setObject:[[structureData objectForKey:connectionName] objectForKey:item] forKey:item];
- if([theConnection getAllKeysOfDbStructure])
- [allSchemaKeys setObject:[[NSSet setWithArray:[theConnection getAllKeysOfDbStructure]] allObjects] forKey:connectionName];
+ NSArray *a = [theConnection getAllKeysOfDbStructure];
+ if(a)
+ [allSchemaKeys setObject:a forKey:connectionName];
} else {
[schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data loaded yet", connectionName]];
[allSchemaKeys setObject:[NSArray array] forKey:connectionName];
@@ -743,7 +745,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
item = schemaData;
}
- if ([item isKindOfClass:[NSDictionary class]] && [item allKeys] && [[item allKeys] count]) {
+ if ([item isKindOfClass:NSDictionaryClass]) {
NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES selector:@selector(localizedCompare:)];
NSArray *sortedItems = [[item allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]];
[desc release];
@@ -758,9 +760,9 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (BOOL)outlineView:(id)outlineView isItemExpandable:(id)item
{
- if([item isKindOfClass:[NSDictionary class]] && [item count]) {
+ if([item isKindOfClass:NSDictionaryClass]) {
// Suppress expanding for PROCEDUREs and FUNCTIONs
- if([item objectForKey:@" struct_type "] && [[item objectForKey:@" struct_type "] intValue] > 1) {
+ if([[item objectForKey:@" struct_type "] intValue] > 1) {
return NO;
}
return YES;
@@ -780,7 +782,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
return [schemaData count];
}
- if([item isKindOfClass:[NSDictionary class]] || [item isKindOfClass:[NSArray class]])
+ if([item isKindOfClass:NSDictionaryClass] || [item isKindOfClass:[NSArray class]])
return [item count];
return 0;
@@ -791,17 +793,20 @@ static SPNavigatorController *sharedNavigatorController = nil;
id parentObject = nil;
- if(outlineView == outlineSchema2 && isFiltered)
- parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaDataFiltered;
- else
- parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData;
+ if(outlineView == outlineSchema2 && isFiltered) {
+ parentObject = [outlineView parentForItem:item];
+ if(!parentObject) parentObject = schemaDataFiltered;
+ } else {
+ parentObject = [outlineView parentForItem:item];
+ if(!parentObject) parentObject = schemaData;
+ }
if(!parentObject) return @"…";
- if ([[tableColumn identifier] isEqualToString:@"field"]) {
+ if ([(NSString*)[tableColumn identifier] characterAtIndex:0] == 'f') {
// top level is connection
- [[tableColumn dataCell] setImage:[NSImage imageNamed:@"network-small"]];
if([outlineView levelForItem:item] == 0) {
+ [[tableColumn dataCell] setImage:[NSImage imageNamed:@"network-small"]];
if([parentObject allKeysForObject:item] && [[parentObject allKeysForObject:item] count]) {
NSString *key = [[parentObject allKeysForObject:item] objectAtIndex:0];
if([key rangeOfString:@"&SSH&"].length)
@@ -815,12 +820,10 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
}
- if ([parentObject isKindOfClass:[NSDictionary class]]) {
- if([item isKindOfClass:[NSDictionary class]]) {
+ if ([parentObject isKindOfClass:NSDictionaryClass]) {
+ if([item isKindOfClass:NSDictionaryClass]) {
if([item objectForKey:@" struct_type "]) {
-
- NSInteger type = [[item objectForKey:@" struct_type "] intValue];
- switch(type) {
+ switch([[item objectForKey:@" struct_type "] intValue]) {
case 0:
[[tableColumn dataCell] setImage:[NSImage imageNamed:@"table-small-square"]];
break;
@@ -837,11 +840,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
} else {
[[tableColumn dataCell] setImage:[NSImage imageNamed:@"database-small"]];
}
- if([[parentObject allKeysForObject:item] count] == 1) {
- return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject];
- } else {
- return @"…";
- }
+ return [[NSArrayObjectAtIndex([parentObject allKeysForObject:item], 0) componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject];
} else {
if([[parentObject allKeysForObject:item] count]) {
@@ -851,9 +850,9 @@ static SPNavigatorController *sharedNavigatorController = nil;
return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject];
} else {
// It's a field and use the key " struct_type " to increase the distance between node and first child
- if(![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "]) {
+ if(![NSArrayObjectAtIndex([parentObject allKeysForObject:item], 0) hasPrefix:@" "]) {
[[tableColumn dataCell] setImage:[NSImage imageNamed:@"field-small-square"]];
- return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject];
+ return [[NSArrayObjectAtIndex([parentObject allKeysForObject:item], 0) componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject];
} else {
[[tableColumn dataCell] setImage:[NSImage imageNamed:@"dummy-small"]];
return nil;
@@ -865,7 +864,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
return [item description];
}
- else if ([[tableColumn identifier] isEqualToString:@"type"]) {
+ else if ([(NSString*)[tableColumn identifier] characterAtIndex:0] == 't') {
// top level is connection
if([outlineView levelForItem:item] == 0) {
@@ -884,12 +883,11 @@ static SPNavigatorController *sharedNavigatorController = nil;
if([outlineView levelForItem:item] == 3 && [item isKindOfClass:[NSArray class]])
{
- NSString *typ = [NSString stringWithFormat:@"%@,%@,%@", [[item objectAtIndex:0] stringByReplacingOccurrencesOfRegex:@"\\(.*?,.*?\\)" withString:@"(…)"], [item objectAtIndex:3], [item objectAtIndex:5]];
+ NSString *typ = [NSString stringWithFormat:@"%@,%@,%@", [NSArrayObjectAtIndex(item, 0) stringByReplacingOccurrencesOfRegex:@"\\(.*?,.*?\\)" withString:@"(…)"], NSArrayObjectAtIndex(item, 3), NSArrayObjectAtIndex(item, 5)];
NSTokenFieldCell *b = [[[NSTokenFieldCell alloc] initTextCell:typ] autorelease];
[b setEditable:NO];
[b setAlignment:NSRightTextAlignment];
[b setFont:[NSFont systemFontOfSize:11]];
- [b setDelegate:self];
[b setWraps:NO];
return b;
}
@@ -975,7 +973,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
// check if selected item is a PROCEDURE or FUNCTION
- else if([selectedItem isKindOfClass:[NSDictionary class]] && [selectedItem objectForKey:@" struct_type "] && [[selectedItem objectForKey:@" struct_type "] intValue] > 1) {
+ else if([selectedItem isKindOfClass:NSDictionaryClass] && [selectedItem objectForKey:@" struct_type "] && [[selectedItem objectForKey:@" struct_type "] intValue] > 1) {
NSInteger i = 0;
NSInteger type = [[selectedItem objectForKey:@" struct_type "] intValue];
NSArray *keys = [selectedItem allKeys];
diff --git a/Source/TableDump.m b/Source/TableDump.m
index a86b5332..11196204 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -754,6 +754,9 @@
// Update current database tables
[tablesListInstance updateTables:self];
+ // Query the structure of all databases in the background
+ [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
+
// Import finished Growl notification
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Import Finished"
description:[NSString stringWithFormat:NSLocalizedString(@"Finished importing %@",@"description for finished importing growl notification"), [filename lastPathComponent]]
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 83e3dde1..e80b7c43 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -863,8 +863,8 @@ closes the keySheet
// Mark the content table for refresh
[tablesListInstance setContentRequiresReload:YES];
- // Query the structure of all databases in the background (mainly for completion)
- [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
+ // Query the structure of all databases in the background
+ [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", selectedTable, @"affectedItem", [NSNumber numberWithInt:[tablesListInstance tableType]], @"affectedItemType", nil]];
return YES;
}