[Core Storage] Apply index sort to fetch request

Apply the index sort to the fetch request itself, rather than applying
it to the resulting array afterward.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-17 17:20:45 -07:00
parent cad6ddac02
commit e9b02d54f4
2 changed files with 7 additions and 8 deletions

View File

@ -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;
}

View File

@ -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])];