Recently, while optimizing my code, I found that performing bulk creates [database putChanges:] dramatically improved the performance when saving multiple documents to my local TouchDB instance. However, I encountered a problem. Following the bulk save, the _rev property of the documents are nil and the model derived from the document cannot execute save. Interestingly, the currentRevisionID property of the document is correct even though _rev is nil.
Here's is my code that retrieves the model after the bulk operation.
2012-10-10 11:56:25.522 MyApp[16231:2c3f] WARNING: Trying to PUT to CouchDocument[3e65..42f2] without specifying a rev ID
2012-10-10 11:56:25.542 MyApp[16231:2c3f] WARNING: One: Save failed: Error Domain=CouchDB Code=409 "The operation couldn’t be completed. conflict" UserInfo=0x11020c80 {NSUnderlyingError=0x11020ed0 "conflict", NSLocalizedFailureReason=conflict}
2012-10-10 11:56:25.543 MyApp[16231:2c3f] save failed, op.error = Error Domain=CouchDB Code=409 "The operation couldn’t be completed. conflict" UserInfo=0x11020c80 {NSUnderlyingError=0x11020ed0 "conflict", NSLocalizedFailureReason=conflict}
Fwiw, I see the document on my remote CouchDB instance with a valid _rev property before this code executes. I have verified that the currentRevisionID (1-00defd215f94b792ee0ad0c87ed22a14) matches the _rev property of the document in my remote CouchDB instance. If I kill and restart my app, the document and model pick up the correct setting of _rev and everything works properly:
If I remove the bulk save (putChanges:, getModelWithID:) and instead create and save the models (alloc, init, putProperties:, save) one at a time, this problem does not occur.
Fwiw, I updated to the latest CouchCocoa and TouchDB-iOS before performing these tests. I'm looking at the code in CouchCocoa to see if I can spot the problem. Seems like it should be something fairly simple but as I'm not familiar with that code, I thought I would post here first.
Recently, while optimizing my code, I found that performing bulk creates [database putChanges:] dramatically improved the performance when saving multiple documents to my local TouchDB instance. However, I encountered a problem. Following the bulk save, the _rev property of the documents are nil and the model derived from the document cannot execute save. Interestingly, the currentRevisionID property of the document is correct even though _rev is nil.
Here's is my code that retrieves the model after the bulk operation.
Here's the output when executed for a document created with putChanges:
A subsequent save generates this output:
Fwiw, I see the document on my remote CouchDB instance with a valid _rev property before this code executes. I have verified that the currentRevisionID (1-00defd215f94b792ee0ad0c87ed22a14) matches the _rev property of the document in my remote CouchDB instance. If I kill and restart my app, the document and model pick up the correct setting of _rev and everything works properly:
If I remove the bulk save (putChanges:, getModelWithID:) and instead create and save the models (alloc, init, putProperties:, save) one at a time, this problem does not occur.
Fwiw, I updated to the latest CouchCocoa and TouchDB-iOS before performing these tests. I'm looking at the code in CouchCocoa to see if I can spot the problem. Seems like it should be something fairly simple but as I'm not familiar with that code, I thought I would post here first.