Hi,
We are seeing some serious performance-issues in the MMObjectNode.getRelated(type)
The way it works now is as follows:
MMObjectNode.getRelated((String type) {
mmbase.get_*ALL*_related_nodes(this)
while(moreElements()) {
if(node.otype = mmbase.getMMObject(type)) // compare the 2 otypes
result.add(node);
}
}
This is fine if the node only has a few related nodes. But what happens with a node
with a smackload of relations but I only want to select, say, the related images..?
Needless to say, this method is highly inefficient.
Another issue arises when inheritance is used for the builders. Consider 2 types
of builders, Persons and Doctors (inher. persons). The current implementation
will fail to deliver the related Doctors when asked to return the Persons (different
otypes).
Proposed sollution:
Rebuild the getRelated to use MultiRelations. Query looks like this:
public Vector getRelatedNodes(String type) {
Vector results = new Vector();
Vector tables = new Vector();
tables.addElement(this.parent.getTableName());
tables.addElement(type);
Vector fields = new Vector();
fields.addElement(type + ".number");
Vector directions = new Vector();
directions.addElement("UP");
String where = "";
// retrieve related nodes of type 'type'
Vector tussenresults = multirelations.searchMultiLevelVector(
getNumber(),fields,"NO",tables,where,new Vector(),directions);
// virtual node -> real node
Enumeration e = tussenresults.elements();
while(e.hasMoreElements())
results.addElement(
this.parent.getNode(((MMObjectNode)e.nextElement()).getStringValue(type+".number")) );
return results;
}
This query will return *only* the valid nodes, instead of all related, discarding the
ones
with a wrong type. And it will fix the inheritance-problems since the tables are
now queried with their names, instead of the selection on otype.
I have implemented this in our system and it seems to run fine. If somebody with
MySql wants to test this, please mail me and I will give the source (or copy the
sample above into MMObjectNode). Rob?
Please discuss :)
gr,
marcel