Another trick to get your Xpage to load faster

On October 20, 2011, in Uncategorized, by Mark Hughes

I HATE  twisties on views on the web!!  I like to use combo-box’s at the top to filter the results.

Recently i ran into an issue getting the values for the combo-box’s.  You see, I used to just do a @DbCloumn to get the values then throw a @Unique() around that  to get my list.  And that seemed to work ok for small views, BUT in this application it had 100k documents and was taking 10-14 seconds to load the page.  I then rethought how I would get values from now on.

The first thing I did was create a new view with one column, the value i needed, and categorized it.  Next I changed the code in the computed values in the combobox to create an array, and use a ViewNavigator to get the values.

//get all end dates and then sort them

var arraydate = new Array()
var view1 = database.getView('enddates')

var nav:NotesViewNavigator = view1.createViewNav();
var entry:NotesViewEntry = nav.getFirst();
while (entry != null) {
	if (entry.isCategory()) {
		arraydate.push(entry.getColumnValues().firstElement().toString())
	}
	var tmpentry:NotesViewEntry = nav.getNextCategory();
	entry.recycle();
	entry = tmpentry;
}

//sort function for dates found on web somewhere
var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
function mdyOrdA(a, b){
a = a.replace(dateRE,"$3$1$2");
b = b.replace(dateRE,"$3$1$2");
if (a>b) return 1;
if (a <b) return -1;
return 0; }

arraydate.sort(mdyOrdA)

 

Notice the use of getNextCategory(), at fist i was using getNextEntry(date1), and that cut the load time in half, using getNextCategory() made it seem to load almost instantaneously.

Now if these values wouldn’t change very often(but they do), i would load this into an applicationScope and let the app check for its existence and only build it when the applicationScope expired.


 

 

 

4 Responses to Another trick to get your Xpage to load faster

  1. Adam Foster says:

    Hi I’d prefer to use a type ahead ajax lookup for this, but another way is to use the little known tip about generating a unique index in a Lotus Notes view to get a faster category lookup.
    See http://www.NotesNinjas.com/#FastCategoryLookup

  2. David Leedy says:

    Adam – I thought there were issues with that generate Unique thing.. Especially if you allow documents to be deleted… That’s a big problem….

    http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/dbfunctions-thing-3?opendocument&comments

  3. Atul Saxena says:

    In general, I do not delete records and prefer to mark it as deletion. I like the way, you used JavaScript, very intuitive method. Thanks for your contribution to Lotus Community.

  4. Jim Romaine says:

    Thanks for this post. I was struggling with an overloaded @Unique as well. This gives me some directions to go next.

Leave a Reply

Your email address will not be published. Required fields are marked *