aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-08-29 21:40:15 +0000
committerrowanbeentje <rowan@beent.je>2011-08-29 21:40:15 +0000
commit1a2439b27b6d0c3d654eb95d42e38deaf597eb80 (patch)
tree126efec7a7490bcbbbf3495043527dcb812048d7
parent667965deb096dfddee663701627eb0364f350a9a (diff)
downloadsequelpro-1a2439b27b6d0c3d654eb95d42e38deaf597eb80.tar.gz
sequelpro-1a2439b27b6d0c3d654eb95d42e38deaf597eb80.tar.bz2
sequelpro-1a2439b27b6d0c3d654eb95d42e38deaf597eb80.zip
- Move table creation to a threaded task, avoiding race conditions caused by loading the new table and loading the structure tab on different threads (log #2266)
-rw-r--r--Source/SPTablesList.m20
1 files changed, 16 insertions, 4 deletions
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 9fc396d5..271b7649 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -2228,6 +2228,15 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
*/
- (void)_addTable
{
+
+ // Ensure the task is performed on a background thread to group addition and loads
+ if ([NSThread isMainThread]) {
+ [NSThread detachNewThreadSelector:@selector(_addTable) toTarget:self withObject:nil];
+ return;
+ }
+ NSAutoreleasePool *tableAdditionPool = [[NSAutoreleasePool alloc] init];
+ [tableDocumentInstance startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Creating %@...", @"Creating table task string"), [tableNameField stringValue]]];
+
NSString *charSetStatement = @"";
NSString *engineStatement = @"";
@@ -2294,8 +2303,8 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
selectedTableName = [[NSString alloc] initWithString:tableName];
selectedTableType = SPTableTypeTable;
- [self updateFilter:self];
- [tablesListView scrollRowToVisible:[tablesListView selectedRow]];
+ [[self onMainThread] updateFilter:self];
+ [[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
// Select the newly created table and switch to the table structure view for easier setup
[tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
@@ -2317,11 +2326,14 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to add the new table '%@'.\n\nMySQL said: %@", @"error adding new table informative message"), tableName, [mySQLConnection getLastErrorMessage]]);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
- [tablesListView reloadData];
+ [[tablesListView onMainThread] reloadData];
}
// Clear table name
- [tableNameField setStringValue:@""];
+ [[tableNameField onMainThread] setStringValue:@""];
+
+ [tableDocumentInstance endTask];
+ [tableAdditionPool release];
}
#ifndef SP_REFACTOR