Posts Tagged ‘performance’

21 Sep 2012
3

LotusScript Tip: Set Readers and Authors Fields in new Documents

Hi Everyone. I’ve been using this forever but I noticed recently that it’s not really common knowledge.

Let’s say you have a Form Design and in it you have a Readers and Authors field. Now let’s also say that you create NotesDocuments for this Form Design in the back-end. The question is: How do you populate a field in LotusScript and turn that field into a READERS or AUTHORS if required.

Many use a famous trick called “ComputeWithForm” which is a method that belongs to the NotesDocument Object. In simple terms, a ComputeWithForm will evaluate the entire NotesDocument against the Form Design it’s associated with….i.e. If you have a Form with 50 Computed Fields that contain various @Formulas, a ComputeWithForm will evaluate each of those Formulas for your NotesDocument Object.

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
Call doc.ComputeWithForm( False )
Call doc.Save( True, True )

 

While this can do the job and save you a lot of coding, a ComputeWithForm can make your code terribly slow depending on how many fields and Computed Values are in the Form and how many documents you plan on computing. I’ve seen a ComputeWithForm take 2 seconds to evaluate 1 NotesDocument. In that time your code could’ve achieved the same goal and a lot more if you wrote your code to not use it. Anyways, moving on.

 

If you didn’t use ComputeWithForm, you would land up having an issue with Readers and Author Fields in your NotesDocument:

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
Call doc.ReplaceItemValue( “CurrentReaders”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CurrentAuthors”, “John Jardin/Ukuvuma” )
Call doc.Save( True, True )

 

If you had to open the DocumentProperties for this Saved NotesDocument and in the Field Properties Tab click on CurrentReaders, you will see it’s a Normal Text Field. This can cause massive issues from an Access point of view.

To solve this problem, we turn to our ever faithful friend…….NotesItem. Using the NotesItem Object, you can set the Field Type in your code. See below Examples 1 and 2:

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
Dim item as NotesItem
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
 
Example 1
 
Call doc.ReplaceItemValue( “CurrentReaders”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CurrentAuthors”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CreatedBy”, “John Jardin/Ukuvuma” )
 
Set item = doc.GetFirstItem(“CurrentReaders”)
item.Isreaders = True
 
Set item = doc.GetFirstItem(“CurrentAuthors”)
item.Isauthors = True
 
Set item = doc.GetFirstItem(“CreatedBy”)
item.Isnames = True
 
Example 2 – (Preferred Option)
 
Set item = New NotesItem( doc, “CurrentReaders”, “John Jardin/Ukuvuma”, READERS )
Set item = New NotesItem( doc, “CurrentAuthors”, “John Jardin/Ukuvuma”, AUTHORS )
Set item = New NotesItem( doc, “CreatedBy”, “John Jardin/Ukuvuma”, NAMES )
 

Also, so you know, SSJS for XPages also has a NotesItem Object that you can use similar to what we’ve done here. I’m not sure about Example 2 though.

Until next time, happy coding

John.

29 Aug 2012
6

Notes Database Performance Tip: Optimize Document Table Map

Hi Everyone. In the past few days I’ve been asked to audit a few Notes Applications. Apart from the usual disabling of unread marks and removing views no longer used to increase performance, there is a very important setting on a Notes Database and can drastically reduce the indexing time of Notes Views.

It’s called “Optimize Document Table Map“.

Firstly, a quick scenario:

Let’s say you have a Notes Application that contains about 5 different Forms. For each form you have about 3 – 5 Notes Views. Also for each Form you have about 5000-10000 documents.

When it comes to indexing Views, if the property “Optimize Document Table Map” is not selected in the Notes Database Properties, the following happens:

When indexing a certain View,  Notes will search through all documents created from all 5 Forms in the Database to produce the result in the View. If you only have a few hundred documents in the database, then this is not an issue. However, 50 000 documents later this could lead to poor performance of your Views.

 

So, let’s say that you have “Optimize Document Table Map” selected in the Notes Database Properties, the following will happen:

When indexing a certain View, Notes will only search through all records in the Database that were created using the Form that’s specified in the View Selection Formula. This means that if you have 5 Forms in the Database, and 5 000 records for each Form, Notes will only search through 5 000 records for a specific Form to index the Notes View. Can you imagine the Response Time :)

 

So, where to enable this setting? If you right-click on your Notes Database and go to the “Database Properties”, click on the last tab. You will see towards the Top that you can check the option “Optimize Document Table Map

 

2 Important Notes when enabling this Setting:

1. I’ve had varied results with enabling this property and just expecting it to work. I highly recommend compacting the database after enabling this Setting just to be sure.

2. In order for this setting to Work, it’s very important that your View Selection Formula for your Notes View specifies the Form Name.

i.e. If your View Selection Formula only says Select FirstName = “John”, then you won’t see a performance boost on the view. However, if you say Select Form = “Person” & FirstName = “John”, this will work because you are referencing the Form Name inside the View, which if you think about it, makes sense.

 

I hope this helps everyone. Happy Coding :)

John

11 Aug 2012
21

XPages Tip: Speed up Design load times by using Design Definitions

Hi everyone. With the merge of the DynamicContent and Switch Custom Controls in the XPages Extension Library, I am more and more practicing the art of adding multiple Custom Controls into a single XPage.

Now, before you shoot me, make sure you understand how the DynamicContent and Switch Control Works. In Short, they Add/Remove designs to your XPage in real time, meaning that you can load a certain Custom Control and its content when you need it, and not on the loading of the XPage. That is awesome stuff, and plays a big role in the performance of one’s XPages Application.

 

But this Post is not about these 2 controls. This Post is about having multiple Custom Controls reside in 1 XPage. Let’s say for whatever reason you have 10 forms that make up your Application, and you have a Custom Control for each Form. What you do now is use 1 XPage, and insert all 10 of these Custom Controls. This is all good and well, except when trying to open up your XPage Design Element in Domino Designer. It become horribly slow, and sometimes my Designer just hangs, forcing me to “Kill Notes”.

The reason for this is because your XPage loads all the design elements and controls that exist inside each of the 10 Custom Controls you added to the XPage, to provide you with a view of more or less how the XPage Looks with all those controls added.

 

So, how do we prevent the Load Time of opening the XPage Design Element? Simple. We use Design Definitions. What is a Design Definition? It’s the ability to make your Custom Control look different when adding it to an XPage, than what it would actually look like when viewing the Custom Control alone.

Let’s say you have a Custom Control that has 30 Combo Boxes running vertically { Please everyone, this is just an example :) }.

You now add this to your XPage, and it looks the same.

A Design Definition allows you to change the look of your Custom Control when it’s added to an XPage or other Custom Control.

Do the following:

1. Open one of your Custom Controls in Designer, and in the Properties Tab, navigate to the “Design Definition” Tab.

2. Add the following Code to the empty Box in this Tab. (All this does is create a div, style it, and add some text inside the Div)

<?xml version=”1.0″ encoding=”UTF-8″?>
<xp:view xmlns:xp=”http://www.ibm.com/xsp/core”
  xmlns:xc=”http://www.ibm.com/xsp/custom”>
<xp:div style=”background-color:blue; color:white; padding:3px;”>This is my Combo Box Custom Control</xp:div>
</xp:view>

3. Save and Close your Custom Control.

4. Open your XPage where the Custom Control exists. If you haven’t added a Custom Control yet, create an XPage and do so.

You’ll see that instead of your Design Elements appearing in the XPage as it would look in the Custom Control, you now have a Blue Box with white Text inside it. If you double click in the Blue Box, you’ll be taken to your Custom Control, where you can view the original Design.

Not only does this keep your XPage tidy when it contains multiple Custom Controls, but it also stops the XPage from having to load all the Design Controls in your Custom Control for viewing in your XPage, which dramatically increases the speed of opening your XPage in Domino Designer.

I hope I didn’t ramble too much in this post. I trust you will find it useful.

Have a good day everyone. Comments, as usual, are always welcome :)

John

15 Mar 2012
2

Use YSlow to measure your Site’s performance and more

Hi Everyone.  Here’s a quick post that I’m sure will make all the difference in your Web Dev Life.

There is a Browser plug-in called YSlow. You can install it on Firefox, Chrome, Safari, Opera and more. I’m going to use the Firefox plug-in for this example.

NOTE: For Firefox, you need to install Firebug to use this plug-in, as it’s an extension to Firebug.

Once you’ve installed the Firebug and YSlow plug-in, and restarted your Browser, do the following:

1. Open your Website. In my example I’m using my XPages Showcase for this example.

2. Push F12 on your keyboard. This will open the Firebug Window at the bottom of the Browser.

3. Click on the YSlow Tab. You’ll see an introduction Page, and a button at the bottom that says “Run Test”. This takes about 2-5 seconds to run.

 

 

4. Once completed, YSlow returns a set of results. You’ll get an overall Grade with a Performance score. (Please don’t judge me for getting a C. YSlow’s moaning at me for not optimizing CSS and JS files,  but there’s a reason for that…)

5. If you take a look at the 3rd Red Arrow on the Image, you’ll see it’s pointing to the Ruleset List. This is pretty awesome, because you can set the rules and benchmark for how your site should be measured. There is a YSlow Add-On called Web Metrics Framework, which is a ruleset that measures your Website according to Google’s Standards.

6. If you go into each of the sections that’s returned….e.g. Content…..you’ll get a second set of Tabs that Score you according to individual operations….See image below.

 

 

7. YSlow also comes with quite a bit of useful Hints, Tips and supporting documentation.

This add-on is easy to navigate, and very very useful. I hope it helps. Thanks Yahoo.

 

Cheers for now.

John