Re: Fast tree scan
Re: Fast tree scan
- Subject: Re: Fast tree scan
- From: Sam Barnum <email@hidden>
- Date: Wed, 31 May 2006 08:59:14 -0700
I should also mention, I'm not sure if this will cause all the EOs to
be flagged as modified, it probably will. I used this technique in a
throwaway editing context which I never called saveChanges() on.
There might be a better way to populate the to-many relationships
without having it be seen as an edit by EOF.
On May 31, 2006, at 8:47 AM, Sam Barnum wrote:
The solution is to fetch all objects with a single fetch, then
populate the "child" relationships for records from the bottom up,
by examining the to-one parent relationship of each EO. Since it's
a to-one relationship, the faults will pull from the cache, and
since you've fetched all EOs, the cache is guaranteed to contain
the parent record, so no round-trip to the DB is needed.
The tricker part is, how do you set the to-many relationships?
Here's some meta-code:
NSArray all = fetchAllRecordsSortedByParentId(); // contains all
records, sorted by parentID
all.takeValueForKey(NSArray.EmptyArray, "children"); // items with
no children should have an empty array
NSMutableArray currentBatch;
Object lastParent;
foreach all AS eachRecord {
if (eachRecord.parent() != lastParent) {
if (currentBatch != null) {
lastParent.setChildren(currentBatch);
}
currentBatch = new NSMutableArray();
lastParent = eachRecord.parent();
}
currentBatch.addObject(eachRecord)
}
On May 31, 2006, at 8:21 AM, Florijan Stamenkovic wrote:
Hi all,
I have an entity that relates to itself, having a parent and
children of the same entity. It works fine.
The intention is that the tree can be used to indefinite depth,
with an indefinite amount of branches. Practically, this measures
let's say ten levels of depth, and involved hundreds of nodes. And
there can be quite a number of trees managed.
At one point however I need to scan the whole tree. That takes a
while because of EOF faulting, where children are not resolved
until they are asked for. Since this is used in a Java Client
scenario, that means that the children for every node cause a trip
to the application server to get the data. It is immensely cheaper
to get it all in one.
My solution was to relate every node to the root node, which is of
a different entity. That way all the nodes belonging to the same
tree can be resolved through one request, regardless of how deep
they are. This however does not help me, because still the
children for every node are faults, and still a round trip is made
when I resolve them.
So, the question is: does anybody know how this can this be
optimized, so that I don't have to have so many round trips?
TIA,
Flor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40360works.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden