Changeset 841

Show
Ignore:
Timestamp:
05/26/09 08:33:44 (15 months ago)
Author:
gbooker
Message:

If no filter is being used, just fetch all entities in the virtual directories. Since auto-pruning is now in place, we don't have to worry about empty directories.

Location:
branches/CoreData/SapphireFrappliance
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/CoreData/SapphireFrappliance/FRAppliance/SapphireApplianceController.m

    r838 r841  
    412412NSArray *showEntityFetch(NSManagedObjectContext *moc, NSPredicate *filterPredicate) 
    413413{ 
    414         NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"tvEpisode != nil"]; 
    415         NSPredicate *finalPred; 
    416         if(filterPredicate == nil) 
    417                 finalPred = fetchPredicate; 
    418         else 
    419                 finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 
    420         NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 
    421  
    422         NSSet *epIds = [NSSet setWithArray:[files valueForKeyPath:@"tvEpisode.objectID"]]; 
    423         NSPredicate *epPred = [NSPredicate predicateWithFormat:@"SELF IN %@", epIds]; 
    424         NSArray *episodes = doFetchRequest(SapphireEpisodeName, moc, epPred); 
    425  
    426         NSSet *showIds = [NSSet setWithArray:[episodes valueForKeyPath:@"tvShow.objectID"]]; 
    427         NSPredicate *showPred = [NSPredicate predicateWithFormat:@"SELF IN %@", showIds]; 
    428  
     414        NSPredicate *showPred = nil; 
     415        if(filterPredicate != nil) 
     416        { 
     417                NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"tvEpisode != nil"]; 
     418                NSPredicate *finalPred; 
     419                if(filterPredicate == nil) 
     420                        finalPred = fetchPredicate; 
     421                else 
     422                        finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 
     423                NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 
     424                 
     425                NSSet *epIds = [NSSet setWithArray:[files valueForKeyPath:@"tvEpisode.objectID"]]; 
     426                NSPredicate *epPred = [NSPredicate predicateWithFormat:@"SELF IN %@", epIds]; 
     427                NSArray *episodes = doFetchRequest(SapphireEpisodeName, moc, epPred); 
     428                 
     429                NSSet *showIds = [NSSet setWithArray:[episodes valueForKeyPath:@"tvShow.objectID"]]; 
     430                showPred = [NSPredicate predicateWithFormat:@"SELF IN %@", showIds]; 
     431        } 
    429432        return doFetchRequest(SapphireTVShowName, moc, showPred); 
    430433} 
  • branches/CoreData/SapphireFrappliance/MetaData/Support/SapphireMovieDirectory.m

    r751 r841  
    3535NSArray *multiMovieEntityFetch(NSString *name, NSString *keyFromMovie, NSManagedObjectContext *moc, NSPredicate *filterPredicate) 
    3636{ 
    37         NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"movie != nil"]; 
    38         NSPredicate *finalPred; 
    39         if(filterPredicate == nil) 
    40                 finalPred = fetchPredicate; 
    41         else 
    42                 finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 
    43         NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 
    44         NSSet *movieIds = [NSSet setWithArray:[files valueForKeyPath:@"movie.objectID"]]; 
    45          
    46         NSPredicate *entPred; 
    47         if([SapphireFrontRowCompat usingTakeTwo] || ![SapphireFrontRowCompat usingFrontRow]) 
     37        NSPredicate *entPred = nil; 
     38        if(filterPredicate != nil) 
    4839        { 
    49                 /*      Damn you Apple for not making take 2 Leopard.  Not only does this make obj C 2 not available, 
    50                         but it also means that I have to content with a crippled and slower core data.  The else block here 
    51                         executes on Leopard at several times the speed, but on Tiger throws the exception: 
    52                         "to-many key not allowed here" even though it can be done through a JOIN in the SQL!!!!!*/ 
    53                 NSPredicate *moviePred = [NSPredicate predicateWithFormat:@"SELF IN %@", movieIds]; 
    54                 NSArray *movies = doFetchRequest(SapphireMovieName, moc, moviePred); 
    55                 NSArray *entSet = [movies valueForKeyPath:[NSString stringWithFormat:@"@distinctUnionOfSets.%@.objectID", keyFromMovie]]; 
     40                NSPredicate *fetchPredicate = [NSPredicate predicateWithFormat:@"movie != nil"]; 
     41                NSPredicate *finalPred; 
     42                if(filterPredicate == nil) 
     43                        finalPred = fetchPredicate; 
     44                else 
     45                        finalPred = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:filterPredicate, fetchPredicate, nil]]; 
     46                NSArray *files = doFetchRequest(SapphireFileMetaDataName, moc, finalPred); 
     47                NSSet *movieIds = [NSSet setWithArray:[files valueForKeyPath:@"movie.objectID"]]; 
    5648                 
    57                 entPred = [NSPredicate predicateWithFormat:@"SELF IN %@", entSet]; 
     49                if([SapphireFrontRowCompat usingTakeTwo] || ![SapphireFrontRowCompat usingFrontRow]) 
     50                { 
     51                        /*      Damn you Apple for not making take 2 Leopard.  Not only does this make obj C 2 not available, 
     52                         but it also means that I have to content with a crippled and slower core data.  The else block here 
     53                         executes on Leopard at several times the speed, but on Tiger throws the exception: 
     54                         "to-many key not allowed here" even though it can be done through a JOIN in the SQL!!!!!*/ 
     55                        NSPredicate *moviePred = [NSPredicate predicateWithFormat:@"SELF IN %@", movieIds]; 
     56                        NSArray *movies = doFetchRequest(SapphireMovieName, moc, moviePred); 
     57                        NSArray *entSet = [movies valueForKeyPath:[NSString stringWithFormat:@"@distinctUnionOfSets.%@.objectID", keyFromMovie]]; 
     58                         
     59                        entPred = [NSPredicate predicateWithFormat:@"SELF IN %@", entSet]; 
     60                } 
     61                else 
     62                        entPred = [NSPredicate predicateWithFormat:@"ANY movies IN %@", movieIds];               
    5863        } 
    59         else 
    60                 entPred = [NSPredicate predicateWithFormat:@"ANY movies IN %@", movieIds]; 
    6164        return doFetchRequest(name, moc, entPred); 
    6265}