我是IBM Domino的新手。我有一个XPages Java应用程序,它用作标准Rooms&Resoruce管理数据库的扩展API(允许我轻松地操纵约会,并且比标准API提供更多功能,例如修改其他人的约会)。
[当我想获取特定房间的所有约会的列表时,我将房间的互联网(邮件)地址传递给我的API,然后在Java应用中,在$(Rooms)
中的names.nsf
视图上进行迭代直到找到包含我要查找的InternetAddress
项目的文档。然后,我从文档中获得了一些其他有趣的信息,例如自动处理设置。
它可以工作,但是我很确定它根本没有效率,我正在查询50多个房间,为所有房间安排约会大约需要18秒钟,对此结果我并不感到真正满意。我该如何优化呢?我很确定我可以在视图上进行一些简单的搜索,从而以更优化的方式完成所有操作,但是我没有足够的经验来使其工作。我当前的代码:
Session session = ExtLibUtil.getCurrentSession();
Database names = session.getDatabase(session.getServerName(), "names.nsf");
View vw = names.getView("($Rooms)");
lotus.domino.ViewNavigator nav = vw.createViewNav();
ViewEntry nextEntry = nav.getFirst();
Document docRoom = null;
while (nextEntry != null) {
ViewEntry processEntry = nextEntry;
nextEntry = nav.getNext();
if (processEntry.isDocument() && processEntry.isValid()) {
docRoom = processEntry.getDocument();
// found
if(docRoom.getItemValueString("InternetAddress").equals(mail)) {
processEntry.recycle();
break;
} else { // not found
processEntry.recycle();
docRoom.recycle();
docRoom = null;
}
} else processEntry.recycle();
}
if(docRoom == null)
return null;
nav.recycle();
String fileName = docRoom.getItemValueString("MailFile");
String fileServer = docRoom.getItemValueString("MailServer");
String fullName = docRoom.getItemValueString("FullName");
您正在所有可用的视图条目上运行50次。因此,这需要太多时间。您的方法的时间复杂度为O(N*M)
。
通过键从视图中获取文档的更有效方法。
Document doc = view.getDocumentByKey(yourKeyValue);
它的运行速度更快(O(LogN)
时间复杂度),但它要求视图应包含具有yourKeyValue
值的第一列。在我们的例子中,我们应该有一个以InternetAddress
作为第一排序列的视图。
很遗憾,($Rooms)
视图不适用于此规则。该视图的第一列包含与我们所需数据不同的数据。
我将在names.nsf
中为该任务创建一个新视图。
将其命名为(RoomsByInternetAddress)
,并将以下公式作为创建的视图的选择公式:
SELECT ((Type = "Database") &(ResourceFlag="1") & (ResourceType="1") & (AutoProcessType != "D")) & (Form="Resource":"Database") & @IsUnavailable($Conflict)
这是($Rooms)
视图的实际公式。
对视图的第一列进行排序,并将第一列的值设置为InternetAddress
字段。
然后保存并关闭它。关闭后,在视图属性(设计器视图列表中)中,启用“禁止刷新或修改设计”。从原始服务器names.nsf
模板刷新后,它将防止新创建的视图被删除。
此后,您无需遍历所有条目。
View vw = names.getView("(RoomsByInternetAddress)");
String InternetAddressIWantToFind = "[email protected]";
Document foundDoc = vw.getDocumentByKey(InternetAddressIWantToFind, true);
if (foundDoc != null) {
// you've found the document by InternetAddress
}