The relevant code is in Andre's response, but in the interest of completeness I will repeat it here:
Dim session As New NotesSession
Dim coll As NotesDocumentCollection
Dim db As NotesDatabase
Dim docCur As NotesDocument, docNext As NotesDocument
Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
Set docCur = coll.GetFirstDocument
Do Until docCur Is Nothing
Call session.UpdateProcessedDoc(docCur)
Set docNext = coll.GetNextDocument(docCur)
' INSERT CODE HERE TO PROCESS A SINGLE DOCUMENT
Delete docCur ' so documents don't accumulate in cache
Set docCur = docNext
Loop
What I'm not clear on, and have not been able to test yet, is whether this also applies to Forall loops and not just GetFirst/GetNext constructs. I also don't typically use NotesViewEntryCollections, so I don't know if it applies to those, either.
SNTT
OK, and what is the performance gain? I know I'll stumble the first few times over the use of "Delete", thinking "Why would they want to delete the document" - only to realize that it's not doc.remove :-P
ReplyDeleteIn an application that looped through 180,000 documents, changed two fields, and saved the documents, adding the Delete reduced agent run time from over 30 minutes by roughly 10 minutes. It seems to help more in long-running situations. I don't know the exact under the hood reason.
ReplyDeleteDelete is definitely a good thing when flipping through large collections. But don't forget about StampAll in NotesDocumentCollection and NotesViewEntryCollection (and their Java equivalents of course), if you are putting a static value or values into all of the docs in the collection. It is incredibly fast.
ReplyDelete