|Quicker, Easier Orphan Deletion of Child Documents|
Tripp W Black on 05/14/2001 at 01:57 PM
Category: Notes Developer Tips
Parent/Child Documents, Agents
|Subject: quicker, easier orphan deletion|
Created by Mark Thomas Schultz on 03/21/2000 at 12:53 PM
Category: Domino Designer -- Agents
Release: Release 5 Platform: - Platform -
Previous forum entries have dealt with the problem of orphaned documents, some solutions stemming the tide by disallowing removal or forcing removal of responses along with main documents (QueryDocumentDelete event of db script), others using script to loop through all documents in a database and eliminating those without parentage.
While both function and have merit, the first method can get to be a usability issue, and doesn't work well when "allow soft deletes" is turned on; while the second method relies on inefficient collection processing and a huge number of document lookups.
A better method is to pull in two parallel collections, then test one against the other *in memory*, removing orphans at the end. The code for this,
Dim s As New notessession
Dim b As notesdatabase
Dim c As notesdocumentcollection, k As notesdocumentcollection
Dim d As notesdocument, t As notesdocument
Const families = "!@IsResponseDoc | @AllDescendants"
Const onlykids = "@IsResponsedoc"
Set b = s.currentdatabase
Set c = b.search( families, Nothing, 0 )
Set k = b.search( onlykids, Nothing, 0 )
Set d = k.getfirstdocument
While Not d Is Nothing
Set t = k.getnextdocument(d)
If Not c.getdocument(d) Is Nothing Then
Set d = t
uses the db.search method to find all unbroken families, then to find all children. Once collected, we loop through all children, find if the child document exists in a good home, and if so, remove it (he, she) from the list of troubled youth.
What remains is a collection of orphans, which can be simply removed using the collection method dc.removeall(force).
<tested for release 5.01+>
I liked the idea of setting this into the db close event, though large databases might cause some performance problems. Better might be to create a simple database with documents that define the databases to be processed -- simple server : pathname pairs. The agent can run regularly (once a night?), looping through all dbs on the server which have been activated. Be sure to log results somewhere.