diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 55379b132..26375e1cc 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -1118,17 +1118,15 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, searchPredicate]]; + NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES]; + NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"]; request.predicate = predicate; + request.sortDescriptors = @[sortDescriptor]; NSError *error = nil; NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error]; - if(results && [results count] > 0) { - NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES]; - results = [results sortedArrayUsingDescriptors:@[sortDescriptor]]; - } - return results; } diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index ff8727929..f907824f7 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -786,6 +786,10 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"]; + NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES]; + + request.sortDescriptors = @[sortDescriptor]; + results = [moc executeFetchRequest:request error:&error]; if(!results) { ALog(@"Error fetching PlaylistEntry objects: %@\n%@", [error localizedDescription], [error userInfo]); @@ -809,9 +813,6 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc [playlistController commitPersistentStore]; } - NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES]; - results = [resultsCopy sortedArrayUsingDescriptors:@[sortDescriptor]]; - { NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [results count])];