I am trying to load JSON from documents in a view and ultimately showing a dojo enhanced data-grid. there are around 1000 documents and I need to check for multiple rows of data. This is legacy application and documents can have details of 80 different users. So my code will generate 80000 Json rows in worst case. Right now it is able to load 70k+ records from 980 documents. My current approach is to create whole JSON and write in a JS variable in browser which is working but it is slow predictably. It takes around 45-80 seconds for Java to generate the JSON.
I changed the approach to load NotesDocument as JSON and parse it on client. This way my java code will loop through only 980 times. I am using document.generateXML() to generate XML and then org.json.XML.toJSONObject() method (this is from json.org jar file) to convert it to JSON. This too is working but it seems to be slower than first approach.
I am not sure how else I can load this much data to browser.
BIGGEST question is : Java code starts executing very long after I open the Xpage. It is called on beforePageLoad event. This I am really worried about. First console message (date-time to check start of code) appears ages after I open the xpage link.
Now for the datagrid, I am displaying 30 rows only but problem is because of multiple rows of data per document I cannot allow users to sort/filter grid until all records are fetched.
Here is my backend Java code for current approach. If you'd like, I can post working code (first approach).
import java.io.IOException;
import java.util.*;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.http.HttpServletResponse;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.View;
import com.ibm.xsp.extlib.util.ExtLibUtil;
import com.ibm.commons.util.io.json.*;
import org.json.*;
/**
* @author agnihotri.a
*
*/
public class AccessRequests {
public static void mainly() {
Date dt1 = new Date();
System.out.println(dt1.toString());
System.out.println("here");
Database database = null;
View accReqView = null;
Document accReqDoc = null;
JSONArray jarr = new JSONArray();
//try out JSONObject here
//List <JSONObject> ljo = new ArrayList<JSONObject>();
try {
/**
* we need handle current user session to compute common name in
* user names field
*/
// Session s = ExtLibUtil.getCurrentSession();
database = ExtLibUtil.getCurrentDatabase();
System.out.println("generating grid in : " + database.getFilePath());
accReqView = database.getView("AccessRequestsGrid");
// get access request document
accReqDoc = accReqView.getFirstDocument();
//int counter = 0;
while (accReqDoc != null) {
//counter++;
jarr.put(org.json.XML.toJSONObject(accReqDoc.generateXML()));
//ljo.add(org.json.XML.toJSONObject(accReqDoc.generateXML()));
accReqDoc = accReqView.getNextDocument(accReqDoc);
}
ExtLibUtil.getSessionScope().put("allAccReq", jarr);
//System.out.println(ljo.size());
//System.out.println(counter);
//ExtLibUtil.getSessionScope().put("totDocs", ljo.size());
}
catch (final Exception ex) {
// tbd: handle exception
ex.printStackTrace();
System.out.println(ex.getStackTrace().toString());
// return "An Error occured. Check with IT team.";
} finally {
// recycle domino objects
KillDomObjects.incinerate(accReqDoc, accReqView, database);
final Date dt2 = new Date();
System.out.println(dt2.toString());
}
}
}