Hello OC,

I would suggest turning the Collection of EOGlobal into primary keys, like this:

// turn global IDs into primary keys (assuming int here, adjust if needed)
var pks = globalIds.stream().map(g -> (int) ((EOKeyGlobalID) 
g).keyValues()[0]).toList();

// create fetch spec with pre-petching relationships
var fetchSpec = new ERXFetchSpecification<SomeEntity>(SomeEntity.ENTITY_NAME, 
null, null);
fetchSpec.setPrefetchingRelationshipKeyPaths(SomeEntity.SOME_RELATIONSHIP);

// fetch EOs in batches, only needed if there are many EOs
var batchIterator = new ERXFetchSpecificationBatchIterator<>(fetchSpec, new 
NSArray<>(pks), ec, 1000);
while (batchIterator.hasNextBatch()) {
    var objects = batchIterator.nextBatch();
    System.out.println("> " + objects.size());
}

The last step using the batch iterator is only needed if you expect a lot of 
EOs (thousands or even more). Otherwise just use a qualifier like 
SomeEntity.ID.in(pks) with a regular fetch.

Best regards,
Stefan


Von: OCsite via Webobjects-dev <webobjects-dev@lists.apple.com>
Antworten an: OCsite <o...@ocs.cz>
Datum: Dienstag, 15. Juli 2025 um 03:35
An: ocs--- via Webobjects-dev <webobjects-dev@lists.apple.com>
Betreff: most efficient way to fetch GIDs?

Hi there,

do please forgive a stupid question, this is probably EOF 101, but I am not 
quite sure of the proper answer.

I've got a Collection of global IDs (it might be any kind of a Collection, from 
an NSArray to a Java Set). All the GIDs represent the same entity, if 
important. And the collection is not recursive (contains just GIDs, never other 
nested collections).

I'd like to turn it into a collection of EOs, as efficiently as possible, 
preferably with at worst one DB round-trip (which needs to include also a 
pre-fetch of a :1 relationship of those objects, if a fetch is needed and the 
data can't be filled from snapshots).

What's the best way to do that? I've tried 
ERXEOControlUtilities.convertGIDtoEO, but for one, it does not seem to properly 
support diverse collections (well I could turn the collection myself into an 
NSArray of course, if need be; but it would be sorta nicer not to have to do 
that), and besides, it does not seem to support a relationship prefetch (or 
perhaps I missed/did something wrong at my side, which is always quite 
probable).

Currently I simply turn all the GIDs into faults, which works properly, but is 
terribly slow when all those faults (and their relationship faults) get fired 
one-by-one later.

Thanks for any suggestion!
OC

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to