Most fast way to iterate view

Dear AllMy client has a database with near 60000 documents included. All theese documents can be accessed in one view. This database grows about 300-400 documents per business day. My task is to create report by iterate all theese documents and make some calculations based on documents fields to create balance list and transaction (turnover) register. I had created agent that allowed to run on server. Code placed below.

Please, tell me, does most effective way to iterate large amount of documents exist? Maybe some tricks or magics?

Dim ns As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim i As Long

Dim sum, sum1 As Currency

Dim oneSum As Currency

Dim FIO As String

Dim color As String

Dim pac As String

Dim action As String

i=1

Sum=0

sum1=0

Set db = ns.CurrentDatabase

Set view = db.GetView("main")

Set doc = view.GetFirstDocument

While Not doc Is Nothing

	oneSum=doc.counter(0)

	color = doc.category(0)

	pac = doc.category_1(0)

	FIO = doc.Category_2(0)

	action = doc.Category_3(0)

	If FIO = "John" Then

		sum = oneSum + sum

	End If

	If FIO = "Joe" Then

		sum1 = 	oneSum+sum1

	End If

’ some similar actions…

	i=i+1

	If (i Mod 3000) = 0 Then

		Print i & " " & Now  ' to timing

	End If

	Set doc = view.GetNextDocument(doc)

Wend

Subject: most fast way to iterate view

Alex,

Your speed will dramatically improve if you set

view.AutoUpdate = False

In theory, view entries should be much faster, but I too have found that this is not always the case. They especially appear to be sensitive to the sort order in the view and where your documents appear in that order. Since you’re going through all the docs in the view, I’m not sure how that’ll pan out.

Also in theory, db.search will be faster because you’re going after 100% of the docs in the database, but I get nervous about holding really large collections of documents in memory, so I’d probably use the method you have, just with AutoUpdate = False.

regards,

raphael

Subject: most fast way to iterate view

The VIEW magazine had a long article on this in the May/June issue this year.

http://www.eview.com/

A couple of things it colncluded that might help you:

setting view.autoupdate = false makes no difference at all

When retrieving values , notesviewentry.columnvalues is the fastest.

The problem with view entries is of course that the larger the views in your db the slower the db gets in general.

Using GetItemValue to get the values from the document instead of the extended syntax actually makes the speed fairly similar to using columnvalues.

Using the extended syntax as you are is the slowest way of doing it.

I’d try out altering your code and using eg:

color = doc.getitemvalue(“category”)(0)

etc.

Also, when using this syntax making sure the case is correct for the field name, apparently this makes a difference.

Worth testing anyway, I haven’t personally tested this exhaustively at all.

hth

dan

Subject: RE: most fast way to iterate view

Dan,

Those results are not consistent with tests which I have run annually against R3, R4, R5, ND6, and ND7. But the exact situation is certainly important. My testing indicates that view.AutoUpdate = False is critical to performance if you’re using the view as your collection … set doc = view.GetNextDocument ( doc )

My testing also indicates that reading the view entries can be faster under some circumstances, but the view setup and how many docs/entries you retrieve and where they are located in the view appear highly relevant.

But always good to get more testing/metrics !

regards,

raphael

Subject: RE: most fast way to iterate view

Hi

As I said these weren’t my results, but from an article in the VIEW magazine.

The test for view.autoupdate false was specifically on just reading data, not making any alterations to any documents which may affect the view in any way (which would make a difference of course).

But then this is still only one other user’s test effectively, and he does also give details on how to test your own applications for speed as no 2 apps are the same.

Dan

Subject: most fast way to iterate view

I believe that iterating through NotesViewEntries will be quicker.

This is especially true if all the data you need is in the columns of the view so you don’t have to have to access the document itself.

From memory, something like this…

dim view as NotesView

set view = db.getView( … )

dim entry as NotesViewEntry

set entry = view.getFirstEntry()

dim values as variant

do until ( entry is nothing )

values = entry.columnValues

color = values(0) ’ column 1 of the view

pac = values(1) ’ column 2 of the view

etc

set entry = view.getNextEntry( entry )

loop

Frunobulax

Subject: Many thanx an benchmark fast view iteration

Many thanx for reply. Right now I make a test.1) iterate by view entries + calculations = 42 sec

  1. “old way” - by getNextDocument + calculations = 28 sec

But I belive that iteration on entries has more stable speed result, than on documents. So pre-conclusion:

  1. if I need a lot of fields for calculations - entries;

  2. if I need one or two fields for calculations - docs.

I will check this conclusion.

Subject: RE: Many thanx an benchmark fast view iteration

look here, interesting article

The DigestSearch method for Lotus Domino databases

JYR

Subject: most fast way to iterate view

How about a completely different approach?

Create a view that categorizes and totals by the FIO field.

e.g.

John 20

Joe 10

Kilroy 52

Give this view to the managers, or if you need to create a report, simply use a NotesViewNavigator to extract the column values without having to read the documents whatsoever.

Subject: RE: most fast way to iterate view

Thanx! It’s realy approach, but I have up to seven “categories” and need to have totals like “category two” on “category one” and “category one” on “category two” and so on. For examplePeter 47$

blocks 12$

board 35$

Mary 8$

board 8$

or

blocks 12$

Peter 12$

board 43$

Peter 35$

Mary 8$

Subject: RE: most fast way to iterate view

That’s still just two views …

However, given the large number of documents, perhaps its better to use your totalling agent.