Commits

Peter Hosey  committed 143e3f0

Make the isLoggingEnabled method not fetch the value from defaults unconditionally (it's fairly expensive, it turns out), but rather, fetch it no less than five minutes apart.

  • Participants
  • Parent commits 6ae6091
  • Branches default

Comments (0)

Files changed (2)

File Core/Source/GrowlLog.h

 
 @interface GrowlLog: NSObject
 {
+	NSDate *lastLoggingEnabledFetchDate;
+	BOOL loggingEnabled;
 }
 
 + (GrowlLog *) sharedController;

File Core/Source/GrowlLog.m

 	return singleton;
 }
 
+- (void) dealloc {
+	[lastLoggingEnabledFetchDate release];
+	[super dealloc];
+}
+
 - (BOOL) isLoggingEnabled {
-	return [[GrowlPreferencesController sharedController] boolForKey:GrowlLoggingEnabledKey];
+	NSDate *now = [NSDate date];
+	if (lastLoggingEnabledFetchDate && ([now timeIntervalSinceDate:lastLoggingEnabledFetchDate] < minimumLoggingEnabledFetchInterval)) {
+		//Not time yet.
+	} else {
+		loggingEnabled = [[GrowlPreferencesController sharedController] boolForKey:GrowlLoggingEnabledKey];
+		[lastLoggingEnabledFetchDate release];
+		lastLoggingEnabledFetchDate = [now retain];
+	}
+
+	return loggingEnabled;
 }
 
 - (void) writeToLog:(NSString *)format withArguments:(va_list)args {