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

Often, entries in this blog are in reaction to questions I get, or someone else's code I've run across. One of the reasons things have been so quiet here is that my job has changed so that's not happening as often. But every now and them I'm reminded that there are things I know that it hadn't occurred to me weren't obvious, until I run across another developer who didn't know it.

That's the case with this tip. Someone mentioned that it was taking their code a long time to scan mail files to see whether there were any design elements that were protected from design refresh/replace (aside from personal folders, where this is expected). I didn't know what they meant by "a long time," so I wrote a few lines of code to scan my mail file, and wrote back that when accessing the file on a server, I couldn't see how to do the search faster than about one or two seconds, and what was their target?

As it turned out, 2 seconds was a considerable improvement over the 220 seconds average they'd been experiencing. The difference was caused by their opening each design note and checking the $Flags and $Class items in it, whereas my code just handed the server a selection formula and let the server do the heavy lifting. Here's my code (using LotusScript because it's my favorite, but it's simple to translate to Java if you're so inclined):

Dim tt As Single

tt = Timer
Dim db As New NotesDatabase("server", "filepath")
Dim nnc As NotesNoteCollection
Set nnc = db.CreateNoteCollection(False)
nnc.SelectAllDesignElements True
nnc.SelectionFormula = { @If(@Contains($Flags; "P") | $Class != ""; $Flags != "3PFY"; @False) }
Print nnc.Count & " found - " & (Timer - tt) & " seconds."

(Of course, if any protected design elements were found, it would take extra time if you wanted to generate a list of their names and types, but just confirming a mail file is "clean" -- that nnc.Count = 0 -- is that fast).

The reason for the difference is the same as the reason it's faster to search for documents using the built-in search functions than to iterate through all the documents in a database; when the server searches, it can use indexes and summary fields, plus it has access to all the documents locally rather than through network transactions. An NSF file also contains an internal index of design elements, very similar to a view, which helps in conducting design element searches (I'm not certain whether that was a factor in this case). If you open a design element using a NotesDocument object, the entire design element has to be fetched from the server. If you use the selection formula, the only information sent back over the network is the list of matching note IDs.

Andre Guirard | 8 January 2013 08:53:07 AM ET | | Comments (0)

Search this blog 


    About IBM Privacy Contact