Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

SNTT: A very fast, very helpful reporting method from the Domino server

By Andrew Pollack on 10/02/2008 at 03:16 PM EDT

I don't do SNTT very often. When I do, its because I think there's some trick or other that you may actually find really useful.

This week, a client needed a report out of a Domino application. There were a lot of ways I could have done this, but the one I chose ended up being very fast and made the client particularly happy. I thought I'd describe it here.

The application is one in which files are posted for users of the site to download. Once made active, the system emails the users a special link. The link is keyed in such a way that the file isn't available unless the user goes through the link to get it (that's done with hash indexing, by the way). A log entry is made when the email goes out, and when a user downloads a file. These log entries are keyed on the unique ID of the user, list the file name and the time of the event.

The report they needed, had to list the user, the file, the date the mail was sent, and the date the file was downloaded (if it was). That's data from three different records. Since we're talking about hundreds -- potentially thousands -- of records, it could take a while to look-up, open, and read all those documents.

I didn't do it that way.

First, I created two views. The first view contains all the uploaded file documents. The first column contains the unique userid, a separator, and the file name -- as a single string, then hashed with @Password. In other words: @Password( uniqueId + "," + @attachmentnames ). The other columns are things I need for the report, including the user's email address, company, and the date the file was posted to the system. The second view contains all the log entries. The first column contains a hash made exactly the same way as the file document one, but with a "1_" prepended if it is a download log, and a "2_" if the file is a mailing log. In otherwords, a mailing log entry would be: "2_" + @Password( uniqueId + "," + @attachmentnames ).

Next, I created an agent, which could be called from a browser. The agent performed these steps:

1. Created a custom class called a "record" like this:


public class record
name as string
email as string
filename as string
filedldate as string
msgsent as string
....(etc)
end class


2. Created a "LIST" of type "record" to hold the data:


dim recordList list as record


3. Created a "LIST" of type "string" to hold the logging data


dim logList list as string


4. Opened the log data view, used the "allEntries" property to get the view entries, and then iterated them. For each entry in the view, I created a matching list entry with the same key. The value of the item was the date that log entry corresponded to. This allowed me to read that view data in one pass into memory without opening a single document. That's extremely fast.

5. Opened the view containing the file upload records, access an entrycollection via the "allEntries" property of the view class, and then iterated through the entries.

6. For each entry, I create a new "record" object and assign it to my RecordList set. I set the properties of that record which are contained in the file records directly from their corresponding view entry columns -- without having to open the actual documents.

7. Next, using the key of that entry, I checked for a "mailing" log entry by adding a "2_" to the key, and checking the logList set to see if one existed. If it did, I could simply assign its value to the record.msgsent property.

8. I did the same as in step 7, only with a "1_" to look for file download records.

9. On finishing that iteration, I have a complete list set of all the data I need without ever actually opening a document.

10. I simply print out the data to the user.

How did I print out the data?

First, as the first lines in the agent, I used this syntax:


Print |Content-Type:application/vnd.ms-excel|
Print |Content-Disposition: Attachment; filename="|+filename+|"|

This overrides Domino sending out html. Once that's done, I created a table:


print "<table><tr>"

And iterated through my recordList, pushing out values:


print "<td>" & record.email & "</td><td>" & record.downloadDate & "</td>"

Etc etc. then after the loop, I closed the table:


print "</tr></table>"


I even used a style tag to make the cells look pretty.


print "<style type='text/css'>"
print " td { border:dotted 1px silver; margin:.5em; font-size:8pt; } "
print "</style>"



When the user clicks the link, they get a nicely formated document launches to Excel in their workstation. They can sort and work with the data any way they like. They're very happy.

Note: I could have done the output during the original loop, which would have been faster if there are a huge number of records -- but since its all in-memory for the second loop, its not really any slower. Its still faster than the data can transfer to the end client. I choose this way to keep it more clean and manageable.


  • text bubble icon

    Security Review

    How secure is your Domino environment? A security review doesn't have to be expensive to be helpful. If you're interested in finding out more, Contact Me.
  • There are  - loading -  comments....

    re: SNTT: A very fast, very helpful reporting method from the Domino serverBy Nick Wall on10/03/2008 at 04:57 AM EDT
    Comment Loading
    re: SNTT: A very fast, very helpful reporting method from the Domino serverBy Andrew Pollack on10/03/2008 at 01:09 PM EDT
    Comment Loading


    Other Recent Stories...

    1. 02/14/2010Great weekend sleddingI'm from "away" -- a term which in Maine speak means that I wasn't born here, and while I've been here for nearly 20 years I am very easily spotted as a non-native to pretty much anyone with long time family roots in the area. Being from away, there are things I just hadn't had a chance to do that most Mainer's take for granted. This weekend, I got the chance to scratch a few of those off the list. These included going 'upta camp', being significantly north of Bangor, and spending a fair bit of time on a ...... 
    2. 02/10/2010Is anyone really considering a move to a hosted Exchange system?I got this press release today from someone I really should learn to just ignore -- but I couldn't help myself. I actually read it. What struck me as the most odd set of statements in it focused on the idea that small and medium businesses are migrating away from Notes and into hosted exchange environments. In other words, that the move for small business into the cloud was somehow based on ISV's hosting off-site Microsoft Exchange mail servers for people. I suppose there must be some out there. This one ...... 
    3. 02/06/2010When does an application stop belonging to its owner?When an application becomes truly successful and people start relying on it for things they consider important, is there a point at which the application starts to belong to the owners? Facebook's latest change brings the topic to mind, but it can happen to you with internal applications as well. There comes a time when users begin to have a personal stake in the design of a good application. Facebook makes a great example for when your users really own your application. Its user base is both extremely ...... 
    4. 01/29/2010Lotusphere 2010 - Session Survey Results 
    5. 01/27/2010Is UPS just plain broken? * Updated 
    6. 01/25/2010My presentations posted here from Lotusphere 2010 
    7. 01/24/2010Me - in bobblehead form 
    8. 01/23/2010Announcing the C.U.L.T. Shirt 2010 Winner 
    9. 01/19/2010Great round table with Kristen Lauria about the Lotus Knows campaign 
    10. 01/19/2010The Review: Lotusphere 2010 – Opening General Session 
    Click here for more articles.....


    pen icon Comment Entry
    Subject
    Your Name
    Homepage
    *Your Email
    * Your email address is required, but not displayed.
     
    Your thoughts....
     
    Remember Me  

    Please wait while your document is saved.