Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Clear CouchDatabase state when it's deleted
Browse files Browse the repository at this point in the history
If the app calls -DELETE on a CouchDatabase, the object needs to forget
its current state, like the document cache and change-tracker.
  • Loading branch information
snej committed Aug 29, 2012
1 parent fa5137b commit 20bb19e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Couch/CouchDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ + (CouchDatabase*) databaseWithURL: (NSURL*)databaseURL {
}


- (void)dealloc {
- (void) close {
self.tracksChanges = NO;
_lastSequenceNumber = 0;
_lastSequenceNumberKnown = NO;
[_busyDocuments release];
_busyDocuments = nil;
[_deferredChanges release];
_deferredChanges = nil;
[_docCache release];
_docCache = nil;
}


- (void)dealloc {
[self close];
[_onChangeBlock release];
[_modelFactory release];
[super dealloc];
Expand Down Expand Up @@ -105,6 +116,19 @@ - (RESTOperation*) compact {
}


- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
error = [super operation: op willCompleteWithError: error];
if (op.isDELETE && !error) {
// Database deleted!
[self close];
}
return error;
}


#pragma mark - DOCUMENTS:


- (NSInteger) getDocumentCount {
id count = [[self GET].responseBody.fromJSON objectForKey: @"doc_count"]; // synchronous
return [count isKindOfClass: [NSNumber class]] ? [count intValue] : -1;
Expand Down

0 comments on commit 20bb19e

Please sign in to comment.