The main part of script is 2000+ lines long so I’ve just included the relevant parts as the rest of it will just cloud the issue.
to DNtpSearchByQuery(msgPrefix, documentLocation, searchQuery)
#Generic function for running a query in DNtp, returning the record count and record List.
#{documentCount, documentList} DNtpSearchByQuery(msgPrefix, documentLocation, searchQuery)
tell application id "DNtp"
set msgPrefix to msgPrefix & "DNtpSearchByQuery|"
set theRecords to search searchQuery in documentLocation
return {count of theRecords, theRecords}
end tell
end DNtpSearchByQuery
to getDocumentByDocumentID(msgPrefix, documentId)
# Search the database for documentID. Return true it exists and the record, or false if
# it doesn't exist
set {successful, documentLocation} to (my getDocumentLocationByDocumentID(msgPrefix, documentId))
if successful then
set {recordCount, recordList} to DNtpSearchByQuery(msgPrefix, documentLocation, "mddocumentid==" & documentId)
if recordCount is 1 then
set theRecord to item 1 of recordList
set theResult to {true, theRecord}
else
set theResult to {false, ""}
end if
else
set theResult to {false, ""}
end if
return theResult
end getDocumentByDocumentID
to createDocument(msgPrefix, documentId)
# Create a new empty document with basic meta data. The record created form a "to-do" item. This
# record needs to be populated from the production Oracle database. But also allows a URL to be
# generated that can be used to reference this documentId going forward
tell application id "DNtp"
set msgPrefix to msgPrefix & "createDocument|"
set {successful, documentLocation} to (my getDocumentLocationByDocumentID(msgPrefix, documentId))
if successful then
set theRecord to create record with {type:"PDF document"} in documentLocation
set custom meta data of theRecord to {mddocumentid:documentId}
my setDocumentDetail(msgPrefix, theRecord, "documentName", "Placeholder for |" & documentId & "|")
my setDocumentDetail(msgPrefix, theRecord, "documentID", documentId)
my setDocumentDetail(msgPrefix, theRecord, "documentRefreshStatus", "New")
return {true, theRecord}
else
return {false, ""}
end if
end tell
end createDocument
to findOrCreateDocument(msgPrefix, documentId)
# Seach DNtp for the documentId. If its found return success and the record, if its
# not found create a new record and return it.
tell application id "DNtp"
set msgPrefix to msgPrefix & "findOrCreateDocument|"
set {successful, theRecord} to my getDocumentByDocumentID(msgPrefix, documentId)
if not successful then
set {successful, theRecord} to my createDocument(msgPrefix, documentId)
end if
return {successful, theRecord}
end tell
end findOrCreateDocument
to createNotesFromPDF(msgPrefix, theRecord)
# Using regex the PDF associated with theRecord looking for matching documet IDs.
# For each document ID discovered search DNtp for that ID in the custom meta data
# field "mdDocumentId". If its found, great, if not create it.
tell application id "DNtp"
set msgPrefix to msgPrefix & "createNotesFromPDF|"
set theFilePath to path of theRecord
my logmsg("d", msgPrefix & "File|" & theFilePath & "|")
set documentIdList to my grepPDF(theFilePath)
set documentIdList to my cleanTheList(documentIdList)
repeat with documentId in documentIdList
my logmsg("d", msgPrefix & "Found Note ID|" & documentId & "|")
set {successful, theRecord} to my findOrCreateDocument(msgPrefix, documentId)
end repeat
end tell
end createNotesFromPDF
my createNotesFromPDF("createNotesFromPDF | ", theRecord)
But Script Debugger times all of the calls, and by far this the longest call, which takes 3.5 - 4 seconds.
search "mddocumentid==136.98-75.1" in parent id 1549626 of database id 2
{content id 1573272 of database id 2}
I do have an undesirable feature in my code at the moment where by it does the search twice. I’m looking to resolve that, but ultimately it’s this 3.5-4 second search time that is killing performance. Everything else is completing in 0.00x seconds.