0

Is saving a CBLModel an expensive operation. How many seconds/milliseconds will it take to save a CBLModel to the database?

CBLModel *model = [database modelForDocument:documentID];
NSError *error;
[model save:&error];
DaveR
  • 9,540
  • 3
  • 39
  • 58
Anonymous
  • 219
  • 2
  • 6
  • Never mind, I was able to find out that there is an operation in Couchbase for bulk save, which is exactly what i wanted – Anonymous Feb 03 '14 at 11:46

1 Answers1

0

If you have many models to save, you may use CouchBaseLite transactions that greatly improve performance.

[database inTransaction:^BOOL()
{
    for ( int i = 0; i < 1000; i++)
    {
        CBLModel *model = ...;
        NSError *error;
        [model save:&error];
    }
    return (YES);
}
];
Laurent
  • 116
  • 1
  • 3
  • + (BOOL) saveModels: (NSArray*)models error: (NSError**)outError;(API available in CBLModel class) Isn't this better? – Ajith Renjala Mar 05 '14 at 08:25
  • Your solution is easier and better ! I had a look at saveModels code in CouchBaseLite, and there is a transaction too. However, the didSave method is not called for any models in case the transaction failed. – Laurent Mar 15 '14 at 18:02
  • With my method, a model may not be saved although its didSave method is called. So yes, your method is better. – Laurent Mar 15 '14 at 18:11