[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>
This commit is contained in:
parent
cad6ddac02
commit
e9b02d54f4
2 changed files with 7 additions and 8 deletions
|
@ -1118,17 +1118,15 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
||||||
|
|
||||||
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, searchPredicate]];
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[deletedPredicate, searchPredicate]];
|
||||||
|
|
||||||
|
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"index" ascending:YES];
|
||||||
|
|
||||||
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
||||||
request.predicate = predicate;
|
request.predicate = predicate;
|
||||||
|
request.sortDescriptors = @[sortDescriptor];
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
NSArray *results = [self.persistentContainer.viewContext executeFetchRequest:request error:&error];
|
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;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -786,6 +786,10 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
||||||
|
|
||||||
request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
request = [NSFetchRequest fetchRequestWithEntityName:@"PlaylistEntry"];
|
||||||
|
|
||||||
|
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES];
|
||||||
|
|
||||||
|
request.sortDescriptors = @[sortDescriptor];
|
||||||
|
|
||||||
results = [moc executeFetchRequest:request error:&error];
|
results = [moc executeFetchRequest:request error:&error];
|
||||||
if(!results) {
|
if(!results) {
|
||||||
ALog(@"Error fetching PlaylistEntry objects: %@\n%@", [error localizedDescription], [error userInfo]);
|
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];
|
[playlistController commitPersistentStore];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES];
|
|
||||||
results = [resultsCopy sortedArrayUsingDescriptors:@[sortDescriptor]];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [results count])];
|
NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [results count])];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue