On May 18, 2014, at 6:33 AM, Ragu Vijaykumar <[email protected]> wrote:
>
> dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,
> 0), ^{
> NSError* error;
> CBLDatabase* database = [[[CBLManager sharedInstance] copy]
> existingDatabaseNamed:@"mydatabase" error:&error];
> [database saveAllModels:&error];
> });
There are a couple of things wrong here --
1. The shared instance of CBLManager should only be used on a single thread
(usually the main thread.)
2. There's an existing method -[CBLManager backgroundTellDatabaseNamed:to:] to
run code on a background thread, so you don't need to go through the work.
3. Even if you do that, this code won't do anything because the background
thread's database instance doesn't have any CBLModels.
Unfortunately there isn't really a clean way to do what you're asking, yet. An
implementation of this would need to collect the -propertiesToSave from each
modified CBLModel, send that data to the background thread and save the
properties to the corresponding CBLDocuments, and then back on the main thread
mark the models as unmodified as soon as the change notification arrives. The
last step in particular is tricky and I don't think it can be done with the
public API.
Are you having performance problems saving? If so I'd love to see some profile
data from Instruments.
--Jens
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/AF09FDA8-6E54-41DC-ACDE-D0318DB2D51E%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.