aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPQueryController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2014-06-23 02:04:50 +0100
committerrowanbeentje <rowan@beent.je>2014-06-23 02:04:50 +0100
commit185a29c013fdf8b43ef7dc5e95da4c1aa8df34e0 (patch)
tree0c2a577b3039c0e0ef10aec474d3663566d92037 /Source/SPQueryController.m
parentd15bf9942f4153b2108d07e50bad6e00f3ac42da (diff)
downloadsequelpro-185a29c013fdf8b43ef7dc5e95da4c1aa8df34e0.tar.gz
sequelpro-185a29c013fdf8b43ef7dc5e95da4c1aa8df34e0.tar.bz2
sequelpro-185a29c013fdf8b43ef7dc5e95da4c1aa8df34e0.zip
Move console button and entry generation to occurring non-synchronously when calling back to the main thread, fixing a potential spinlock situation when a background thread is querying and the main thread is waiting on the result
Diffstat (limited to 'Source/SPQueryController.m')
-rw-r--r--Source/SPQueryController.m24
1 files changed, 15 insertions, 9 deletions
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index feaa1624..f31ce808 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -44,6 +44,7 @@ NSString *SPTableViewConnectionColumnID = @"messageConnection";
@interface SPQueryController ()
- (void)_updateFilterState;
+- (void)_allowFilterClearOrSave:(NSNumber *)enabled;
- (BOOL)_messageMatchesCurrentFilters:(NSString *)message;
- (NSString *)_getConsoleStringWithTimeStamps:(BOOL)timeStamps connections:(BOOL)connections;
- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error;
@@ -438,8 +439,7 @@ static SPQueryController *sharedQueryController = nil;
[progressIndicator startAnimation:self];
// Don't allow clearing the console while filtering its content
- [saveConsoleButton setEnabled:NO];
- [clearConsoleButton setEnabled:NO];
+ [self _allowFilterClearOrSave:[NSNumber numberWithBool:NO]];
[messagesFilteredSet removeAllObjects];
@@ -451,8 +451,7 @@ static SPQueryController *sharedQueryController = nil;
[consoleTableView reloadData];
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
- [saveConsoleButton setEnabled:YES];
- [clearConsoleButton setEnabled:YES];
+ [self _allowFilterClearOrSave:[NSNumber numberWithBool:YES]];
[saveConsoleButton setTitle:NSLocalizedString(@"Save As...", @"save as button title")];
@@ -484,8 +483,7 @@ static SPQueryController *sharedQueryController = nil;
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
if ([messagesVisibleSet count] > 0) {
- [saveConsoleButton setEnabled:YES];
- [clearConsoleButton setEnabled:YES];
+ [self _allowFilterClearOrSave:[NSNumber numberWithBool:YES]];
}
[saveConsoleButton setTitle:NSLocalizedString(@"Save View As...", @"save view as button title")];
@@ -497,6 +495,15 @@ static SPQueryController *sharedQueryController = nil;
}
/**
+ * Enable or disable console save and clear buttons
+ */
+- (void)_allowFilterClearOrSave:(NSNumber *)enabled
+{
+ [saveConsoleButton setEnabled:[enabled boolValue]];
+ [clearConsoleButton setEnabled:[enabled boolValue]];
+}
+
+/**
* Checks whether the supplied message text matches the current filter text, if any,
* and whether it should be hidden if the SELECT/SHOW toggle is off.
*/
@@ -592,13 +599,12 @@ static SPQueryController *sharedQueryController = nil;
&& [self _messageMatchesCurrentFilters:[consoleMessage message]])
{
[messagesFilteredSet addObject:[messagesFullSet lastObject]];
- [[saveConsoleButton onMainThread] setEnabled:YES];
- [[clearConsoleButton onMainThread] setEnabled:YES];
+ [self performSelectorOnMainThread:@selector(_allowFilterClearOrSave:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:NO];
}
// Reload the table and scroll to the new message if it's visible (for speed)
if (allowConsoleUpdate && [[self window] isVisible]) {
- [[self onMainThread] updateEntries];
+ [self performSelectorOnMainThread:@selector(updateEntries) withObject:nil waitUntilDone:NO];
}
pthread_mutex_unlock(&consoleLock);