Iterating documents based on a view object has become very slow in later years. Maybe because of all the work that has been with NIF-index issues.
The following techniques show poor (some even very poor) performance when running in the client against a server database:
Set
view = dbSource.Getview(
"vCategoryOneCategory"
)
Set
vec = view.Getallentriesbykey(
"Documents"
,
True
)
Set
ve = vec.Getfirstentry()
While
Not
ve
Is
Nothing
Let
lCount = lCount +
1
Set
ve = vec.Getnextentry(ve)
Wend
Set
doc = view.Getfirstdocument()
While
Not
doc
Is
Nothing
Let
lCount = lCount +
1
Set
doc = view.Getnextdocument(doc)
Wend
Set
nav = view.Createviewnav()
Set
ve = nav.Getfirst()
While
Not
ve
Is
Nothing
Let
lCount = lCount +
1
Set
ve = nav.Getnext(ve)
Wend
Whereas the following show good (even very good) performance:
Set view = dbSource.Getview("vCategoryOneCategory")
Let view.Autoupdate = False
Set nav = view.Createviewnavfromcategory("Documents")
Let nav.Buffermaxentries = BUFFER_MAX_ENTRIES
Set ve = nav.Getfirst()
While Not ve Is Nothing Let lCount = lCount + 1
Set ve = nav.Getnext(ve)
Wend
Let view.Autoupdate = True
Set view = dbSource.Getview("vCategoryOneCategory")
Set dc = view.Getalldocumentsbykey("Documents",True)
Set doc = dc.Getfirstdocument()
While Not doc Is Nothing
Let lCount = lCount + 1
Set doc = dc.Getnextdocument(doc)
Wend
In very large databases the search takes longer, the looping is always fast.
Set dc = dbSource.Search(strFormula,Nothing,0)
Set doc = dc.Getfirstdocument()
Do Until doc Is Nothing
Let lCount = lCount + 1
Set doc = dc.Getnextdocument(doc)
Loop
In most circumstances, it's a good idea to disable auto-update (i.e. view.Autoupdate = False) before entering a loop over view entries. Looks to me like this is the main reason why your third last example performs best.
Your last and second to last examples are of different, because there you are looping over collections, not view entries.
Can you provide more context or information for "Maybe because of all the work that has been with NIF-index issues."
It is only slow on one version or it always slow when you run the query?