I have an NSArray (arrayOfUnreadArticleIdentifiers) with 8249 strings, which are NSString (articleIdentifier) properties on my Article object, which is an RLMObject subclass. I need to fetch all articles with articleIdentifier that is in arrayOfUnreadArticleIdentifiers. So, my first thought was to do the following :-
[Article objectsInRealm:realm withPredicate:[NSPredicate predicateWithFormat:@"articleIdentifier IN %@", arrayOfUnreadArticleIdentifiers]];
However that throws an invalid predicate/invalid query exception.
After a bit of trial & error, I find that there is a limit to the number of strings I can have in arrayOfUnreadArticleIdentifiers (2507 in my case), so, doing the following makes my predicate/query valid again :-
[Article objectsInRealm:realm withPredicate:[NSPredicate predicateWithFormat:@"articleIdentifier IN %@", [arrayOfUnreadArticleIdentifiers objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2507)]]]];
My first question/request: I would love some details about the limits of the IN Operator in Realm.
Another observation I have made while retrofitting my existing Core Data app with Realm..
The following method, with my current dataset, takes approximately 80 seconds to complete the query when articleIdentifier is not indexed, and approximately 78 seconds when it is indexed :-
[Article objectsInRealm:realm withPredicate:[NSPredicate predicateWithFormat:@"articleIdentifier IN %@", [arrayOfUnreadArticleIdentifiers objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2507)]]]];
While..
I have a RLMArray category, which has a method which looks like this :-
-(NSSet *)setOfAllObject
{
NSMutableSet *set = [NSMutableSet new];
for (id object in self)
{
[set addObject:object];
}
return [set copy];
}
And, if I use the following method and do the filtering in-memory, it takes approximately 13 seconds, with the same dataset (Note: I don't limit the array I pass in the IN predicate) :-
[[[Article allObjectsInRealm:realm] setOfAllObject] filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"articleIdentifier IN %@", arrayOfUnreadArticleIdentifiers]];
So, I guess my second question is: Is this something I could be doing wrong where in-memory filtering is significantly faster?