Hello,
I have a requirement where I have 2 databases. db.nsf and db2.nsf.
db.nsf has 960,000 documents. db2.nsf has 300,000 documents. I have to get a key value from db.nsf, and search in db2.nsf, and update the flags accordingly.
I have defined the following algorithm, and have a code also. The code works fine, but it runs for atleast 8-10 hrs or a day. I am not sure why. I have following questions,
Is there a way that I can improove the processing time by making changes in this code?
This line, Print "Proccessing document # - " + Cstr(count%) - Shows me Processing document # - 32767. But count then does not changes, but I can see the different fieldvalue1 upon next document. The counter works fine from 1…32767, but then stops increamenting, I am not sure why? Since the agent runs for hours and hours, I have set an email which will give me an update, how many docs have been processed? But since the count is not going further after 32767, I can not figure out how many documents have been processed?
Algorithm
Get the key from view ALL within db.nsf
Search in db2 for a key from db.nsf
If the count >= 3 then,
3.1
Update a flag “dbvalidemail” within db2.nsf
3.2
Update a flag “dbemailbounced” within db2.nsf
3.3
Update a flag “dbvalidemail” within db.nsf
If the count = 0 then,
4.1
Update a flag “dbvalidemail” within db
AGENT CODE -
Sub Initialize
Dim varray() As String
Dim it As NotesItem
Dim i As Integer
Dim vc As NotesViewEntryCollection
Dim strProdNo As String
Dim ns As New NotesSession
Dim ndt As New NotesDateTime ("") 'a time for our notes document and log messages
Dim theTime As String 'a string for the time
Dim errorlog As NotesLog
Dim doc2 As NotesDocument
Set db = ns.Currentdatabase
Set errorlog = ns.Createlog("logdb")
Set logdb = New Notesdatabase (db.server, "logdatabase.nsf" )
theTime$ = ndt.LocalTime
Dim view As NotesView
Dim doc As NotesDocument
Set view = db.GetView( "ALL" )
Set vc = view.AllEntries
count% = 0
X = 1
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
count% = count% + 1
Print "Proccessing document # - " + Cstr(count%)
Print doc.fieldvalue1(0)
val$ = doc.fieldvalue1(0)
If (doc.HasItem ("fieldvalue2") And doc.fieldvalue2(0) <> "") Then
Call check(doc)
End If
If X = 10000 Then
Call SendMail( count% )
X = 1
End If
Set doc = view.GetNextDocument( doc )
X = X + 1
On Error Goto this
Wend
this:
Call errorlog.Opennoteslog(db.Server, "logdatabase.nsf")
errorlog.Logaction("Agent Started" + " at "& theTime$+ "Key is, "+ doc.fieldvalue1(0) +" created using form, "+ doc.Form(0) +" has doc id "+ doc.UniversalID + "for user - " + doc.eu_first_name(0) + " " +doc.eu_last_name(0)) 'begin logging
Call errorlog.Close
Print "Resume on error"
Resume Next
Exit Sub
End Sub
Sub check ( req As NotesDocument )
Dim view1 As NotesView
Dim dc As NotesDocumentCollection
Dim doc1 As NotesDocument
Dim item, item1, item2 As NotesItem
Dim db2 As NotesDatabase
Set db2 = New NotesDatabase( "IP ADDRESS", "db2.nsf" )
Set view1 = db2.GetView("ALL")
query$ = req.email(0)
j = view1.FTSearch(query$, 0 )
Set dc = view1.GetAllDocumentsByKey(req.fieldvalue1(0))
If ( dc.Count >= 3 ) Then
Set doc1 = dc.GetFirstDocument()
Set item2 = req.AppendItemValue("dbvalidemail", "No")
While Not(doc1 Is Nothing)
Set item = doc1.AppendItemValue("dbvalidemail", "No")
Set item1 = doc1.AppendItemValue("dbemailbounced", "Yes")
Call doc1.Save( False, True )
Call req.Save( False, True )
Set doc1 = dc.GetNextdocument(doc1)
Wend
Elseif ( dc.Count = 0 ) Then
Set item = req.AppendItemValue("dbvalidemail", "Yes")
Call req.Save( False, True )
End If
End Sub
Sub SendMail (Count As Integer )
Dim emaildb As NotesDatabase
Dim emaildoc As NotesDocument
Dim emailsession As New NotesSession
Set emaildb = emailsession.CurrentDatabase
Set emaildoc = New NotesDocument( emaildb )
emaildoc.Form = "Memo"
emaildoc.SendTo = "user's name"
emaildoc.Subject = "Agent Status Update - " & Cstr(Count)
Call emaildoc.Send( False )
End Sub
Thanks
MS