From 1ecd2ebc5c03bf369e0951923d966eecf04a2925 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 18 Jun 2009 09:15:12 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20CMMCPConnection:=20observeValu?= =?UTF-8?q?eForKeyPath:@"ConsoleEnableLogging"=20-=20now=20[delegate=20wil?= =?UTF-8?q?lQueryString:]=20will=20only=20be=20called=20if=20user=20set=20?= =?UTF-8?q?=20ConsoleEnableLogging=20to=20YES=20(~8%=20faster)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --Note: this option to disable logging should be placed in the Import dialog with default = NO for importing as well --- Source/CMMCPConnection.h | 1 + Source/CMMCPConnection.m | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 6d0b0811..26590d85 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -74,6 +74,7 @@ BOOL retryAllowed; BOOL delegateResponseToWillQueryString; + BOOL consoleLoggingEnabled; IMP willQueryStringPtr; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 68056ba1..18d89e8b 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -276,6 +276,7 @@ static void forcePingTimeout(int signalNumber); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:) name:@"SMySQLQueryWillBePerformed" object:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL]; return mConnected; } @@ -681,6 +682,16 @@ static void forcePingTimeout(int signalNumber); } +/** + * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. + */ +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([keyPath isEqualToString:@"ConsoleEnableLogging"]) { + consoleLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"ConsoleEnableLogging"]; + } +} + /* * Override the standard queryString: method to default to the connection encoding, as before, * before pssing on to queryString: usingEncoding:. @@ -726,8 +737,9 @@ static void forcePingTimeout(int signalNumber); // queryStartTime = clock(); - // Inform the delegate about the query - if (delegateResponseToWillQueryString) + // Inform the delegate about the query if logging is enabled and + // delegate responds to willQueryString: + if (consoleLoggingEnabled && delegateResponseToWillQueryString) (void)(NSString*)(*willQueryStringPtr)(delegate, @selector(willQueryString:), query); // Derive the query string in the correct encoding -- cgit v1.2.3