I was analyzing performances of my app with Instruments and i noticed that a method needs a lot time to be completed, this method is [CBLDatabase(Internal) notifyChanges:] (see the attached photo below).
There is a way to disable it? In particular because i assume that method is used for live queries feature and i don't currently use it.
On Jul 15, 2015, at 6:48 AM, Daniel Sonny Agliardi <dan...@gmail.com> wrote:I was analyzing performances of my app with Instruments and i noticed that a method needs a lot time to be completed, this method is [CBLDatabase(Internal) notifyChanges:] (see the attached photo below).
There is a way to disable it? In particular because i assume that method is used for live queries feature and i don't currently use it.
On Jul 16, 2015, at 12:59 AM, Daniel Sonny Agliardi <dan...@gmail.com> wrote:This "issue" happens when i do about 30 UPDATE queries in a for.
- (BOOL)saveExeciseTemplate:(ExerciseTemplate *) exerciseTemplate{
NSError *error;
// create an object that contains data for the new document
NSDictionary *myDictionary = [[exerciseTemplate asDictionary] copy];
// Create an empty document
CBLDocument *doc = [[self getDatabase] documentWithID:exerciseTemplate.name];
// Save the ID of the new document
NSString *docID = [[myDictionary objectForKey:@"template_id"] copy];
// Write the document to the database
if(myDictionary && doc){
//DDLogInfo(@"Saving ID = %@...", docID);
CBLRevision *newRevision = [doc putProperties: myDictionary error:
&error];
if (newRevision) {
//DDLogInfo(@"Document created and written to database, ID = %@", docID);
//return true;
}
if (error) {
//DDLogInfo(@"Document NOT created, error = %@", error.localizedDescription);
//if this exerciseTemplate is already in DB, then update it
if (error.code == 409) {
[doc deleteDocument:&error];
doc = [[self getDatabase] documentWithID:docID];
CBLSavedRevision *newRev = [doc putProperties:myDictionary error:&error];
if (!newRev) {
//DDLogInfo(@"Cannot update document. Error message: %@", error.localizedDescription);
} else {
//DDLogInfo(@"Document updated and written to database, ID = %@", docID);
return true;
}
}
}
}
return false;
}
NSURLSessionDataTask *exerciseTask = [[SessionManager sharedSessionManager] GET:EXERCISE_LIST_PATH parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
NSDictionary *JSON = (NSDictionary *)responseObject;
[self parseExercises:JSON];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
DDLogError(@"Could not load exercises!");
}];
- (void)parseExercises:(NSDictionary *)JSON {
NSArray *tempArray = [JSON valueForKey:@"exercises"];
for (NSDictionary *dict in tempArray) {
ExerciseTemplate *template = [[ExerciseTemplate alloc] init];
NSString *exerciseName = [dict valueForKey:@"name"];
NSString *exercise_id = [dict valueForKey:@"id"];
NSNumber *dynamic = [dict valueForKey:@"dynamic"];
NSNumber *uniateral = [dict valueForKey:@"unilateral"];
NSString *content = [dict valueForKey:@"content"];
NSNumber *repetitionMaximum = [dict valueForKey:@"repetition_maximum"];
NSDictionary *thresholdDict = [dict valueForKey:@"thresholds"];
NSDictionary *polygonDict = [dict valueForKey:@"polygon"];
template.name = exerciseName;
template.template_id = exercise_id;
template.dynamic = dynamic.boolValue;
template.unilateral = uniateral.boolValue;
template.content = content;
template.repetitionMaximum = repetitionMaximum.floatValue;
template.thresholdDict = thresholdDict;
template.polygonExplosiveness = [polygonDict objectForKey:@"ex"];
template.polygonPower = [polygonDict objectForKey:@"po"];
template.polygonResistance = [polygonDict objectForKey:@"re"];
template.polygonStrength = [polygonDict objectForKey:@"st"];
template.polygonVelocity = [polygonDict objectForKey:@"sp"];
//[transaction setObject:template forKey:template.template_id inCollection:EXERCISE_TEMPLATE_COLLECTION];
[[TPADatabaseManager sharedManager] saveExeciseTemplate:template];
//}];
}
}
Basically my problem is that the given UPDATE method (found here http://developer.couchbase.com/mobile/develop/training/build-first-ios-app/do-crud/index.html#update) raises an error (409 - conflict) so I'm not able to proper UPDATE documents in database with some new versions of properties. I came up with a DELETE + INSERT to archive the same result of an UPDATE as you can in posted code.
I think the the point is: DELETE and INSERT have a way bigger notification time (I refer to my performance issue) then just an update, even if you put both operations in a single transaction.
If can help me first, I can, maybe, fix this problem sooner by remove the DELETE and INSERT operations.
(Ps I write in upper case the SQL's primitive function/operation that I used to handle, to, hopefully better, explay what I want to say)
On Jul 22, 2015, at 10:58 AM, Daniel Sonny Agliardi <dan...@gmail.com> wrote:Basically my problem is that the given UPDATE method (found here http://developer.couchbase.com/mobile/develop/training/build-first-ios-app/do-crud/index.html#update) raises an error (409 - conflict)
I came up with a DELETE + INSERT to archive the same result of an UPDATE as you can in posted code.
Basically I have to do 2 UPDATEs and in both cases I have only the main thread using DB.
There is a way to find out the reason 409 error in my code? The UPDATE seems pretty easy to understand (getting document, extract properties, update locally the properties, and put properties back in document).
Do the entire UPDATE method in a transaction can help? I haven't tried this way.
On Sep 2, 2015, at 10:48 AM, Daniel Sonny Agliardi <dan...@gmail.com> wrote:
How can I send you our project if you are so gentle to help us with DB performance issues?
Thank you.
On Sep 22, 2015, at 8:59 AM, Daniel Sonny Agliardi <dan...@gmail.com> wrote:
No, i have not opened a issue on Github, because i still don't understand if this issue is my fault (due to an inefficient algorithm i used to insert or update records in DB or something other) or not.