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)

Search this blog 


    About IBM Privacy Contact