Search code examples
core-dataafnetworkingnsfetchrequestafincrementalstore

AFIncrementalStore and a ton of Core Data fetches


I've been using AFIncrementalStore and decided to profile my Core Data fetch requests. I have no idea why the number of requests would be so large. Any fundamentals I might be screwing up?

enter image description here


Solution

  • I believe I've figured out the problem. I'm using the service Parse as my backend but wasn't overriding -requestForFetchRequest: to add a where clause. I only wanted items associated with the currently logged in user. This seems to have fixed things.

    - (NSURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest withContext:(NSManagedObjectContext *)context {
        NSMutableURLRequest *request = [[super requestForFetchRequest:fetchRequest withContext:context] mutableCopy];
        NSString *whereUserId = [NSString stringWithFormat:@"where={\"userId\":\"%@\"}",[PFUser currentUser].objectId];
        [request setHTTPBody:[whereUserId dataUsingEncoding:NSUTF8StringEncoding]];
        return request;
    }
    

    Now I've got a fetch request for the initial load and when I select each item. Much more appropriate.