Permalink
Browse files

Clear CouchDatabase state when it's deleted

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...
1 parent fa5137b commit 20bb19e3ead536089460c021c720aa99000538cf @snej snej committed Aug 29, 2012
Showing with 25 additions and 1 deletion.
  1. +25 −1 Couch/CouchDatabase.m
View
@@ -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];
@@ -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;

0 comments on commit 20bb19e

Please sign in to comment.