Split the work into 2 jobs per computer to retrieve assets faster

This commit is contained in:
Cameron Gutman
2015-11-13 19:52:35 -08:00
parent e6aa16ad01
commit a8bcc6afba

View File

@@ -696,13 +696,31 @@ static NSMutableSet* hostList;
_sortedAppList = [host.appList allObjects];
_sortedAppList = [_sortedAppList sortedArrayUsingSelector:@selector(compareName:)];
// Start populating the box art cache asynchronously
// Split the sorted array in half to allow 2 jobs to process app assets at once
NSArray *firstHalf;
NSArray *secondHalf;
NSRange range;
range.location = 0;
range.length = [_sortedAppList count] / 2;
firstHalf = [_sortedAppList subarrayWithRange:range];
range.location = range.length;
range.length = [_sortedAppList count] - range.length;
secondHalf = [_sortedAppList subarrayWithRange:range];
// Start 2 jobs
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Log(LOG_I, @"Starting per-computer box art caching job");
for (App* app in host.appList) {
for (App* app in firstHalf) {
[self updateBoxArtCacheForApp:app];
}
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (App* app in secondHalf) {
[self updateBoxArtCacheForApp:app];
}
Log(LOG_I, @"Per-computer box art caching job completed");
});
[hostScrollView removeFromSuperview];