source: branches/CoreData/SapphireFrappliance/MetaData/SapphireMObjects/SapphireGenre.m @ 623

Revision 623, 1.3 KB checked in by gbooker, 6 years ago (diff)

Optimizations. Use a predicate for fetching files since it can be faster (aggregate SQL accesses)

Line 
1#import "SapphireGenre.h"
2#import "CoreDataSupportFunctions.h"
3#import "SapphireFileSorter.h"
4#import "SapphireMovie.h"
5
6@implementation SapphireGenre
7
8static NSArray *allowedSorts = nil;
9
10+ (void)load
11{
12        allowedSorts = [[NSArray alloc] initWithObjects:[SapphireMovieTitleSorter sharedInstance], [SapphireDateSorter sharedInstance], [SapphireMovieIMDBRatingSorter sharedInstance], nil];
13}
14
15+ (SapphireGenre *)genre:(NSString *)genre inContext:(NSManagedObjectContext *)moc
16{
17        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", genre];
18        return (SapphireGenre *)doSingleFetchRequest(SapphireGenreName, moc, predicate);
19}
20       
21+ (SapphireGenre *)createGenre:(NSString *)genre inContext:(NSManagedObjectContext *)moc
22{
23        SapphireGenre *ret = [SapphireGenre genre:genre inContext:moc];
24        if(ret != nil)
25                return ret;
26       
27        ret = [NSEntityDescription insertNewObjectForEntityForName:SapphireGenreName inManagedObjectContext:moc];
28        ret.name = genre;
29        return ret;
30}
31
32- (NSPredicate *)metaFileFetchPredicate
33{
34        NSArray *movieIds = [self.moviesSet valueForKey:@"objectID"];
35        return [NSPredicate predicateWithFormat:@"movie IN %@", movieIds];
36}
37
38- (NSArray *)fileSorters
39{
40        return allowedSorts;
41}
42
43- (NSString *)path
44{
45        return [super.path stringByAppendingPathComponent:self.name];
46}
47
48@end
Note: See TracBrowser for help on using the repository browser.