Fix Playlist Loader so it only attempts to process track info for tracks that need it, and not the entire playlist every time

This commit is contained in:
Christopher Snowhill 2021-04-06 16:50:17 -07:00
parent 282252bfe7
commit ce8a1c230d

View file

@ -309,7 +309,7 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
} }
else else
{ {
[expandedURLs addObject:url]; [expandedURLs addObject:[NSURL fileURLWithPath:[url path]]];
} }
} }
} }
@ -472,14 +472,19 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
- (void)syncLoadInfoForEntries:(NSArray *)entries - (void)syncLoadInfoForEntries:(NSArray *)entries
{ {
NSMutableIndexSet *update_indexes = [[NSMutableIndexSet alloc] init]; NSMutableIndexSet *update_indexes = [[NSMutableIndexSet alloc] init];
long i; long i, j;
NSMutableIndexSet *load_info_indexes = [[NSMutableIndexSet alloc] init];
i = 0; i = 0;
j = 0;
for (PlaylistEntry *pe in entries) for (PlaylistEntry *pe in entries)
{ {
long idx = j++;
if ([pe metadataLoaded]) continue; if ([pe metadataLoaded]) continue;
[update_indexes addIndex:pe.index]; [update_indexes addIndex:pe.index];
[load_info_indexes addIndex:idx];
++i; ++i;
} }
@ -490,21 +495,21 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
return; return;
} }
{ [load_info_indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop)
for (PlaylistEntry *pe in entries)
{ {
PlaylistEntry *pe = [entries objectAtIndex:idx];
NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:20]; NSMutableDictionary *entryInfo = [NSMutableDictionary dictionaryWithCapacity:20];
NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL]; NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:pe.URL];
if (entryProperties == nil) if (entryProperties == nil)
continue; return;
[entryInfo addEntriesFromDictionary:entryProperties]; [entryInfo addEntriesFromDictionary:entryProperties];
[entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]]; [entryInfo addEntriesFromDictionary:[AudioMetadataReader metadataForURL:pe.URL]];
[pe setMetadata:entryInfo]; [pe setMetadata:entryInfo];
} }];
}
[self->playlistController updateTotalTime]; [self->playlistController updateTotalTime];