Hello, I have a stream of data (some messages) from a socket and I
need to save it in a CoreData db. I would to optimize this thing by
using more than a managedobjectcontext for each N messages arrived.
The problem is that I need to link these message between
(parent/childs). How can I check if a message exist in a context
without merge it with the main context? Need I to mantain an array of
active contexts and comunicate with them in order to search parents
and childs? If I merge each time with the main context it's a bit
slow.

Well, you can create the messages and save them in groups in their own thread and MOC, and link them up with their parents later. Or you can organize the background threads to own parent groupings and have those dedicate threads save their messages.

The problem with inserting messages and relating them to parents haphazardly is that the to-many relationship on Parent will need to merge in the results on each save anyway, and having lots of threads banging on the same to-many will just engender a lot of merge conflicts. While the right merge policy will resolve them for you, that's not remotely free. You can look up a previously saved MO with - objectWithID: on your MOC.

If you have a very large number of messages, you may not wish to model the to-many on Parent at all.

- Ben

_______________________________________________

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