adium 5575:395f9e5b1109: Download Twitter avatars on the LOW dis...

commits at adium.im commits at adium.im
Fri Jun 14 17:31:09 UTC 2013


details:	http://hg.adium.im/adium/rev/395f9e5b1109
revision:	5575:395f9e5b1109
branch:		adium-1.5.7
author:		Thijs Alkemade <me at thijsalkema.de>
date:		Fri Jun 14 19:30:44 2013 +0200

Download Twitter avatars on the LOW dispatch queue and use a semaphore to limit it to 16 concurrent downloads. This should avoid Adium deadlocking when downloading avatars for >64 contacts on Twitter.

diffs (27 lines):

diff -r 4044634d3b95 -r 395f9e5b1109 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m	Wed Jun 12 21:53:57 2013 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m	Fri Jun 14 19:30:44 2013 +0200
@@ -1032,12 +1032,22 @@
 		
 		[listContact setValue:[NSNumber numberWithBool:YES] forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
 		
+		static dispatch_semaphore_t imageDownloadSemaphore;
+		static dispatch_once_t onceToken;
+		dispatch_once(&onceToken, ^{
+			imageDownloadSemaphore = dispatch_semaphore_create(16);
+		});
+		
 		// Grab the user icon and set it as their serverside icon.
-		dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+		dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
 			NSString *imageURL = [url stringByReplacingOccurrencesOfString:@"_normal." withString:@"_bigger."];
 			NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]];
 			NSError *error = nil;
+			
+			dispatch_semaphore_wait(imageDownloadSemaphore, DISPATCH_TIME_FOREVER);
 			NSData *data = [NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:&error];
+			dispatch_semaphore_signal(imageDownloadSemaphore);
+			
 			NSImage *image = [[[NSImage alloc] initWithData:data] autorelease];
 			
 			if (image) {




More information about the commits mailing list