Hi there!
I have a problem with filtering deleted documents on a push replication.
I have a very simple filter that prevents pushing documents to the sync gateway based on a property. In Swift:
private func setContactsFilter() {
self.database.setFilterNamed(SyncManager.cloudContactsFilter) { rev, _ in
guard let props = rev.properties as? [String: AnyObject] else {
return true
}
return SyncManager.shouldSyncContact(props)
}
}
class func shouldSyncContact(properties: [String: AnyObject]) -> Bool {
if let type = properties["type"] as? String where type == "contact" {
return false
}
return true
}
(The if
is a bit more complex than that, but you get the idea.)
Now when I delete a document that was never synced, the filter function “fails” to prevent it from syncing, since the document does not have any properties anymore. The deleted document get synced to the database instead of just being forgotten.
I am not sure how to fix this.
- Should I use
purgeDocument
instead ofdeleteDocument
for those cases where I don’t want to deletion to be synced? This means that the code that deletes the document should be aware of the filter. I don’t like that - Should I use
parentRevision
in my filter when the revision is a deletion? Will it always work? What if the parent revision has been purged already?
Any ideas how to solve this?
Thanks