[CORE DATA] multithreading
[CORE DATA] multithreading
- Subject: [CORE DATA] multithreading
- From: Aurélien Hugelé <email@hidden>
- Date: Tue, 28 Feb 2006 12:12:35 +0100
Hi list and al!
I've read almost all posts on this list about core data, but subtle
details still puzzle me. I hope someone can clarify things (again?)
When i launch my app, currently, a spotlight query is started (in the
main thread) to try to import new emails (all new emails since date:
initialDate)
Then, when i know the new emails file pathes, i parse them and import
their informations (sender, recipients, subject etc...) in a SQLite
Core Data database.
The problem here is that importing of my datas is quite slow, and
since everything is done in the main thread, as soon as the app is
launched, the UI is not immediatly responsive.
What is blocking the UI (about 10-15 second on a fast G5) is:
1/ a fetch to avoid reimporting an already imported email (each email
has a uniqueId in its header, so the fetch has a "uniqueId IN
{ .. .. .. ..}" predicate type),
2/ several fault firing slowness that i have optimized as most as i
can, and these optimizations are already efficient (for exemple, i
prefetch some relationships to the sender and recipients since they
are going to be modified when i'll add a new email and save about 2-3
min for a large import)
Now, i want to thread the import phase to keep the UI non blocking.
Shortly, i have respected the basic "rules": one MOC per thread,
sharing one PSC. Never pass NSManagedObjects between threads, but use
objectIDs instead.
But i have some problem to understand if I have to synchronize both
MOC manually or not and how? i mean, should i insert in the main
thread moc (using [moc1 insertObject:[moc1 objectWithID:objectId]])
the objects i inserted in the threaded moc (ie moc2, using
insertNewObjectForEntityForName:inManagedObjectContext:) ? from what
i have read on this list, i have to synchronize mocs, nothing is done
for me.
From my test, to make the main thread array controller aware of the
new objects, i have to use insertObject: on the moc1.
what happens if i delete an object in the threaded moc (moc2) ? how
should i synchronize moc1 ? i suppose i can not use objectWithID:
because the object has been deleted!? i've seen some code using
refreshobject:mergeChanges: ...
should i perform moc save: twice ? once in each thread ?
wouldn't be clever to use notifications ? but notifications use
NSInsertedObjectsKey and not objectIDs...
I think BackgroundFetching sample code is a great start, but only
explains how to do background fetching... nothing a little bit more
complex :) we would like apple to feed us with explanations on MOC
synchronizing !!!!!!!
Thanks!
Aurélien _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gumitech.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden