On Sat, Feb 13, 2010 at 4:06 AM, Roland King <r...@rols.org> wrote:

> That's not a horrible solution, except for the feeling that core data ought
> to let you do what you want without having to implement your own UUID cache.
> I'm still a bit surprised that a lookup for an object by one attribute is
> taking so long, over just 30,000 objects. You do have the uuid attribute
> marked as indexed right?
>
> I found
> http://cocoawithlove.com/2008/03/testing-core-data-with-very-big.htmlwhilst 
> hunting around for some examples of core data with big data sets.
> This guy was working on sets of 1 million objects and doing fetches with
> indexed properties was taking about 2 seconds, vs non-indexed, 600 seconds.
> There are some comments at the bottom from an apple engineer too.
>

Hi Roland,
Uhmmm probability there is something wrong with my code, because with
indexed messageid property it takes a very long time too (I can't see any
visible difference, 20k messages took minutes to be completed)
Here you will found my simple storage data model:
http://img197.imageshack.us/img197/4388/screenshot20100213at111.jpg

This is my code:
for (NSString *cMessage in messagedata) {
NSString *idd = [cMessage headerValueFor:ARTICLE_TAG_ID]; // takes the
MESSAGE UUID
if ([thegroup articleForID:idd inCtx:ctx] == nil) { // CHECK IF MESSAGE UUID
IS ALREADY ON DB
MCArticle *c = [MCArticle newArticleWithID:idd context:ctx]; // WE CAN MAKE
THE MESSAGE AND ADD IT TO COREDATA

// WE WANT TO CHECK FOR PARENT
NSString *parentidms = [[[f headerValueFor:ARTICLE_TAG_REFS]
reverseOrderedReferences] objectAtIndex:0];
MCArticle *parent = [thegroup articleForID:parentidms inCtx:ctx]; // WE
QUERY FOR PARENT UUID
if (parent != nil) {
// LINK BOTH PARENT AND CHILD
}
}
}

ArticleForID:inCtx: method follow (inCtx is required becase these functions
works in a multithreading environment)
(I've also tried to re-use fetchRequest object but it's not the main
problem...)

- (MCArticle *) articleForID:(NSString*) _msgid
inCtx:(NSManagedObjectContext*) ctx {
if (_msgid == nil) return nil;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setFetchLimit:1];
[fetchRequest setEntity: [NSEntityDescription entityForName:@"MCArticle"
inManagedObjectContext:ctx]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"messageid ==
%@",_msgid];
[fetchRequest setPredicate: predicate];
NSArray *results = [ctx executeFetchRequest:fetchRequest error:nil];
[fetchRequest release];
if ([results count]==0)return nil;
return [results objectAtIndex:0];
}

Finally the init method for Message object:

+ (MCArticle *) newArticleWithID:(NSString *) _messageID
context:(NSManagedObjectContext *) _context {
MCArticle *oj = (MCArticle*)[[NSManagedObject alloc]
initWithEntity:[NSEntityDescription entityForName:@"MCArticle"
  inManagedObjectContext:_context]
   insertIntoManagedObjectContext:_context];
[oj setValue:_messageID forKey:@"messageid"];
return oj;
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to