How can I optimize this code? Also have a documentcollection failing

I was just given some really old agent (notes in it dated 1995, geez I was a freshman in HS then). Its a cleanup agent that scrolls through everyones maildb in the company and deletes every document older than some set amount of days.

Theres a good chunk of code that checks certain conditions to be sure it should delete a maildb. There are certain ones that are exempt for random reasons. That codes not bad. Some gotos but they are all linear and no spagetti. A lot of calls to a lot of Subs declared in the agent itself. Its still faster to put those in a script library, correct?

In the actual Sub that deletes the documents in a maildb there is some code I dont know much about, well anything. Know that it works, mostly anyways else I wouldnt be looking at it, but I dont know how efficient any of it is.

Mainly this: NotesDatabase.Search

At first I assumed that finding docs that are older than some set date would be some single condition statement. But I was obviously wrong when I looked at how many things they put in the $searchstring thats given to NotesDatabase.Search. Something like this:


searchFormula$ = "!@IsMember(Form; "

'for the @IsMember funtion to use. The Chr(34) below is the double quote.

Forall FormName In ExemptForms

searchFormula$ = searchFormula$ & Chr(34) & FormName & Chr(34) & " : "

End Forall

searchFormula$ = searchFormula$ & Chr(34) & “Junk” & Chr(34) & ") & "

searchFormula$ = searchFormula$ & "(RetainDocument != 1) & " &_

“(DeliveredDate < @Adjust(@Today;0;0;” & Cstr(-days2%) & ";0;0;0) | " & _

“PostedDate < @Adjust(@Today;0;0;” & Cstr(-days2%) & ";0;0;0) | " &_

“DueDateTime < @Adjust(@Today;0;0;” & Cstr(-days2%) & ";0;0;0) | " &_

“(PostedDate != null & @Created < @Adjust(@Today;0;0;” & Cstr(-days2%) & “;0;0;0)))”

Set collection = MailDB.Search( searchFormula$, dateTime, 0 )


Ive read in a few posts its generally slow so giving it this giant formula must really slow it down.

I still have to sift through all that to see what that does exactly.

Whats another way to do a DB.search? Create a view then just cycle through each document in the view?

I dont think anyone will let me update the mail database template to do that though =(

Also, the agent is failing somewhere whenever it hits a MailDB that is > than 4gigs. Im guessing its failing right on the “Set collection = MailDB.Search(…)” when .search returns too many.

So I guess thats an even better reason to get rid of .Search.

Any input would be greatly appreciated.

Thanks

Subject: How can I optimize this code? Also have a documentcollection failing

db.seach is slow because data isnt indexed for it; but all the other solutions as far as I know requires you to atleast be able to modify he template a little bit in order to create a hidden shared view that will contain your selection criteria before the agent runs.

As for the 4GB limit, sounds like the mail db simply reached its quota; depending on your Notes version that can be extended; but you may have to re-create a replica with the new extended limit.

I am not sure why it cannot run when the limit is reached; it probably has to write some information on the database to perform the search…

HTH

Nicolas Abesdris

Quintessence e-solutions Inc.

Subject: RE: How can I optimize this code? Also have a documentcollection failing

Thanks. I have to figure out exactly what line is dying on the large maildbs. If its the documentcollection I can probably push to have a mail template refresh. I’ll just have to push hard.