marcoarment / FCModel

An alternative to Core Data for people who like having direct SQL access.
MIT License
1.65k stars 173 forks source link

Maybe -begin/endNotificationBatch should be per thread? #73

Closed ahti closed 10 years ago

ahti commented 10 years ago

I am not having any actual problems with this right now, but think of this scenario:

There is a sync engine, that syncs the local database with a webservice. After downloading a set of changes, it merges them into the local database. It wraps this in a notification batch to only notify the UI once after the sync completed.

Now, while the sync engine is going through a big set of changes, the user makes a change in the ui, which would normally cause a notification to fire that tells other parts of the ui to update. But since the sync engine is busy, this notification is delayed until it finishes syncing.

This potential problem could be addressed by making -beginNotificationBatch and -endNotificationBatchAndNotify: affect the thread they are called on only.

I think this change would make a lot of sense, but I am not quite sure wether there are any drawbacks. Just throwing it out there.

PS: I think it would also be nice to have another block-based method something like this:

[FCModel performBlockWithBatchedNotifications:^{
    // do some changes
} andNotify:YES];
marcoarment commented 10 years ago

Good point. This will probably take a bit of work, but I think you're right that it needs to be done. I'll see what I can do today.

marcoarment commented 10 years ago

As I think about this, I think the move to thread-specific scope should actually require the block-based call, removing the old methods.

marcoarment commented 10 years ago

Turned out to be really easy. Thanks again.