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