adium/adium

Parents 4044634d3b95
Children 76290dac1189
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.
--- 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) {