Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

Jörg Asmussen writes:

 ...I heard ...that using a date vs. Nothing would actually perform something like 2 searches, one for the date and one for the {criteria}.
...I've been removing hundreds of hardcoded dates with Nothing. I hope [that was a good idea]

It is a good idea. To clarify for all you folks out there in blog-land, here's an example of what not to do:

Dim db As New NotesDatabase("Katmandu","somedocs.nsf")
Dim collection As NotesDocumentCollection
Dim dateTime As New NotesDateTime(Cstr(Datenumber(2000, 5, 1)))
Set collection = db.Search("@IsResponseDoc",dateTime,0)
This is an example of what not to do

(Embarrassingly, this example comes straight from the Domino Designer help -- I'm in a Sametime chat even now with the person who maintains this document, to get her to emphasize the best practice by changing the hardcoded date to "in the last month".)

As Jörg thought, it does take time to do a search by last modified date. It doesn't take very long normally, because we keep a sorted list of documents by date modified, which agents and replication use to grab the stuff that's modified since they last ran. But if the search returns all the documents in the database, it probably takes some time to put the results together, as opposed to just using the existing "collection of all documents". So supplying a date that's earlier than all of your documents as a way of saying "all the documents," is inefficient.

Now, the selection of documents by recent modified date is much, much faster than going through the same documents with a formula. So it does make sense to use the date argument if it actually eliminates a large number of documents so that the formula doesn't need to be evaluated for those documents. Of course, it is rare that a hardcoded date is going to be useful in that context -- the only time I can imagine that making sense is for a one-time agent to fix documents created since some date when a bug was introduced. And of course, if you're only going to run an agent once, it doesn't make sense to worry much about performance.

So, as a general rule, please don't use a hardcoded date for a NotesDatabase.Search. Here's the right way to search all documents regardless of modified date:

Dim db As New NotesDatabase("Katmandu","somedocs.nsf")
Dim collection As NotesDocumentCollection
Set collection = db.Search("@IsResponseDoc", Nothing, 0)
Please do it this way instead!

Andre Guirard | 24 April 2007 11:00:00 PM ET | Plymouth, MN, USA | Comments (2)


1) Thanks for the clarification
Charles Robinson | 4/25/2007 9:46:59 AM

Now I understand why putting in a date of something like 01/01/2000 in a database that was deployed in the last 12 months took longer than using Nothing. I can see the cutoff date being useful in cases where you only want documents from the last week/month/quarter, etc.

I sincerely appreciate you digging deeper into this issue and sharing what you found.

2) This almost never comes up for me
Joseph LeMay | 4/26/2007 6:44:56 AM

when I need to build a collection of documents, I usually just build a view and sort it by some key, then use notesView.GetAllDocumentsByKey(key). Is this inefficient? I can't think of a time I've used I suppose adding another view increases the size of the db, and gives it another view to index, which can cause a performance hit, but I haven't run into a situation yet where this has really slowed things down noticeably.

 Add a Comment
Comment:  (No HTML - Links will be converted if prefixed http://)
Remember Me?     Cancel

Search this blog 


    About IBM Privacy Contact