Over the last few days there have been a few releases of the OpenNTF Domino API. One of the issues was something I first came across on Friday evening where Factory.getSession() was throwing an error when triggering a partial refresh from a button in a brand new database. It was fine the first attempt after starting the HTTP task, but failed consistently thereafter. But it was fine in the demo database. The only difference was that in the demo database the implicit objects – session, database, opensession and opendatabase – we’re being loaded but not in my new database. After various attempts to diagnose the cause and changing code, changing the xsp.properties, somehow I managed to get it working. Typically, I then change the code back, and it worked.
Then Monday evening, the problem returned. With the help of Nathan as a sounding board and more detailed logging, I noticed something very strange. The implicit objects were being loaded after the SSJS and Java code was running. A hypothesis occurred to me: were the implicit objects being lazy-loaded, so only loaded when a call was made to database or session (because I had set godmode)? I added one line of code before the line that was failing –
var db=database;. The code worked.
I then pushed the test further. I changed the line of code to
var db=@Left("test","t");. If you’ve watched the NotesIn9 I did on VariableResolvers you’ll know even @Functions in SSJS are parsed via the VariableResolver. It still worked. If I took it out, it failed. I had a dataContext computed on page load. If I changed it to dynamic, my code worked. If I changed it back it failed. By pure coincidence I had optimised my XPage so there were no calls to the VariableResolver during a partial refresh.
So the lesson learned is that VariableResolvers are even more optimised than I had anticipated, so they’re only loaded if there’s a call to a variable. Otherwise the Java code to register and initialise all the objects and SSJS methods is never run, giving a further performance gain.
And in M3.6 the mechanism for registering the XPages session for Factory.getSession() to retrieve has been changed, so it’s no longer dependent on the VariableResolver and registration of the implicit object session.