IBM Support

Slow performance when looping via GetNthDocument in Notes

Technote (FAQ)


Question

In Notes, you find that looping through a NotesView or NotesDocumentCollection using GetNthDocument results in increasingly sluggish performance as the loop progresses.

Answer

The decreased performance occurs when you use GetNthDocument to loop through a large NotesDocumentCollection or NotesView. The GetNthDocument method uses the first document in a collection as a reference point every time it is called. It then steps through all the documents until it reaches the Nth document. If you need to loop through a number of documents, you will experience better preformance using GetFirstDocument and GetNextDocument (instead of GetNthDocument).
Two sample scripts are illustrated below. The second script (using GetFirstDocument and GetNextDocument) will complete more quickly than the first script (using GetNthDocument).

Script 1: Using GetNthDocument:

Dim session As New NotesSession
Dim col As NotesDocumentCollection
Dim db As NotesDatabase
Dim doc1 as NotesDocument

Dim x as Integer

Set db = session.CurrentDatabase
Set col = db.AllDocuments
x = x + 1

Set doc1 = col.GetNthDocument(x)

While Not ( doc1 Is Nothing )
   x = x + 1

    Set doc1 = col.GetNthDocument(x)
Wend


Script 2: Using GetFirstDocument and GetNextDocument:

Dim session As New NotesSession
Dim col As NotesDocumentCollection
Dim db As NotesDatabase
Dim doc1 as NotesDocument

Dim doc2 as NotesDocument

Set db = session.CurrentDatabase
Set col = db.AllDocuments

Set doc1 = Col.GetFirstDocument
Set doc2 = doc1

While Not ( doc2 Is Nothing )
    Set doc2 = col.GetNextDocument(doc1)        
    Set doc1 = doc2
Wend

Historical Number

137906

Product Alias/Synonym

Lotus Notes Client

Document information

More support for: IBM Domino Designer

Software version: 6.0, 6.5, 7.0, 8.0, 8.5, 9.0

Operating system(s): Windows

Reference #: 1099588

Modified date: 28 July 2015


Translate this page: