PermaLink Creating an empty NotesDocumentCollection10/25/2006 10:40 AM
Show-n-tell thursday
Since Thomas Adrian posted about this in swedish, I thought I'd post about it in english. Thanks for the tip, Thomas!

Thomas, like most of us, has used his own approach to creating an empty NotesDocumentCollection, since there is no New constructor for this class. I thought that my approach to it was better, since he used NotesDatabase.FTSearch, which could potentially take a lot of time. Instead, I use the NotesDatabase.GetProfileDocCollection.

Sub Initialize Dim ns As New NotesSession Dim db As NotesDatabase Dim dc As NotesDocumentCollection Set db = ns.CurrentDatabase Set dc = db.GetProfileDocCollection("Foo") End Sub
This LotusScript was converted to HTML using the ls2html routine, provided by Julian Robichaux at nsftools.com.

This will give you an empty NotesDocumentCollection, as quickly as possible. Using NotesDatabase.GetProfileDocCollection has the advantage of searching through only the profile documents of the database (of course), and since profile documents are cached, this should be the fastest, and simplest, way to create an empty collection. Make sure to use a profile name (where I have used "Foo") that doesn't exist in your database, and you will be certain that the collection is empty.

Update: Follow-up

This page has been accessed 794 times. .
Comments :v

1. Sean Burgess2006-10-25 16:54:11
Homepage: http://www.phigsaidwhat.com/


I wonder if doing the following line might be a little "cleaner":

Set dc = db.Search(|@Nothing|,nothing,0)

I haven't tried it myself, but use the Select @Nothing for views that I want to use as templates.

Sean---




2. Peter von Stöckel2006-10-25 20:15:03


Wouldn't it still do a search/index through all documents, which would take time?




3. Tim Tripcony2006-10-26 17:57:04
Homepage: http://www.timtripcony.com


I tried Sean's approach on a database with nearly 5,000 documents and it took less than a second.




4. Nathan T. Freeman2006-10-26 18:52:21
Homepage: http://www.openntf.org/nathan/escape.nsf


Actually, the second parameter is a cutoff date/time. Notes maintains an index of modification times for all docs because the replicator needs it. So searching with a cutoff modification date in the future should be ultra-fast.<br><br>Dim futureDate As New NotesDateTime("01/01/3001")<br>Set dc = db.Search(|@Nothing|,futureDate, 0)<br><br>I'd want to test to figure out which was faster, though. You'd need an NSF with a LOT of profile docs to really find out.

Tim, 5000 isn't nearly enough to gauge actual performance differences. You might start gaining insight with 100 times that.




5. Peter von Stöckel2006-10-27 09:37:15


I'd really like to see a real comparison of the different ways to get a NotesDocumentCollection, so if anyone has a really big database, with at least 100 000 to 200 000 documents, and also lots of profile documents, it would be great to get a comparison.

@Tim: How much less than a second? Do you have any actual timing, since that would be really helpful?

@Nathan: Setting a future date might make a big difference, but then again, it might not. It depends on how Domino uses that information, doesn't it?




6. Nick Wall2006-10-27 12:49:38


Hope this is of some use...

I ran some brief tests on a production DB that contains approx 107,000 documents, loads of views, constantly being updated, etc.
Server : Domino 6.5.3 on Win 2003, Intel 2.8Ghz, 4Gb RAM

The stopwatch class (I have been using for ages now, I think from a "The View" article, there may be minor bit of overhead for this class).

Here is what I ran:
Dim db_sites As New NotesDatabase( "yupodom1/yupo", "Projects\CPM\Sites.nsf" )
Dim futureDate As New NotesDateTime("01/01/3001")

Dim dc_sites_1 As NotesDocumentCollection
Call g_stopWatch.Start( {Method 1} )
Set dc_sites_1 = db_sites.Search({@Nothing},futureDate, 0)
Call g_stopWatch.Stop( {Method 1} )

Dim dc_sites_2 As NotesDocumentCollection
Call g_stopWatch.Start( {Method 2} )
Set dc_sites_2 = db_sites.Search( {@Nothing},Nothing, 0 )
Call g_stopWatch.Stop( {Method 2} )

Dim dc_sites_3 As NotesDocumentCollection
Call g_stopWatch.Start( {Method 3} )
Set dc_sites_3 = db_sites.GetProfileDocCollection("abcdefgh")
Call g_stopWatch.Stop( {Method 3} )


Here are the results - the server was under a light load during the testing.
N.B. The DB has no profile docs so test 3 shows that if you have a large db and no profile docs, it absolutely flies!!! Could run a test for a DB loaded with profile docs. Using a future date as Nathan suggested, certainly speeds up the search(), compared to using a default of nothing.

So, i my environment the quickest to slowest was always : method 3, 1 then 2.

I initialise empty collections quite a bit, so Peter, nice tip.

seconds % calls secs/call event
===========================================================================
00000.985 100.0% 0000001 00000.985 Total run time
00000.953 096.8% 0000001 00000.953 Method 2
00000.032 003.2% 0000001 00000.032 Method 1
00000.000 000.0% 0000001 00000.000 Method 3
===========================================================================
00000.922 100.0% 0000001 00000.922 Total run time
00000.891 096.6% 0000001 00000.891 Method 2
00000.031 003.4% 0000001 00000.031 Method 1
00000.000 000.0% 0000001 00000.000 Method 3
===========================================================================
00000.922 100.0% 0000001 00000.922 Total run time
00000.891 096.6% 0000001 00000.891 Method 2
00000.031 003.4% 0000001 00000.031 Method 1
00000.000 000.0% 0000001 00000.000 Method 3
===========================================================================
00000.906 100.0% 0000001 00000.906 Total run time
00000.875 096.6% 0000001 00000.875 Method 2
00000.031 003.4% 0000001 00000.031 Method 1
00000.000 000.0% 0000001 00000.000 Method 3
===========================================================================
00001.235 100.0% 0000001 00001.235 Total run time
00001.188 096.2% 0000001 00001.188 Method 2
00000.047 003.8% 0000001 00000.047 Method 1
00000.000 000.0% 0000001 00000.000 Method 3

etc., etc.




7. Peter von Stöckel2006-10-27 19:01:20


@Nick: Truly impressive test results! Very nice job! As you say, it would be very interesting to see the results with a db loaded with profile docs as well.

It also seems that the future date really speeds up the search method, which is also very useful information. Maybe not for this use, but it tells us that if we know the cutoff date, we should use it when using the db.Search method.




Add Manual Trackback
Please enter the details of the trackback post. Your trackback will not appear on the site until it has been verified. This won't be immediate, as trackbacks are validated on a scheduled basis. Be patient.











Banana Home
klaseliten.gif

About me
Please ignore this link: webadresser
Banana Applications
Me on Notes.Net
Other stuff
By Category
Monthly Archive
Contact Me
BlogRoll
Technorati tags
Lotus Domino ND8 Lotus Domino ND7 RSS News Feed Blog Admin Lotus Geek OpenNTF BlogSphere