• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: most efficient way to fetch GIDs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: most efficient way to fetch GIDs?


  • Subject: Re: most efficient way to fetch GIDs?
  • From: Ondra Cada via Webobjects-dev <email@hidden>
  • Date: Tue, 15 Jul 2025 15:30:59 +0200

Thanks a lot!

I should get thousands EOs very rarely, mostly just hundreds; thus I did create
the fetch specification with ERXInQualifier.newInstance('uid', pks as NSArray),
and then use plain ec.objectsWithFetchSpecification(fs) to fetch.

It works nicely, but there's one weird drawback — for just 391 records I
currently test against this takes more than 5 seconds. That seems way too much;
the pre-fetched relationship is a simple modelled :1 with a FK in the fetched
entity matching PK of the other one, and most (quite probably all) of the
fetched records should have the same EO for its target; that should be pretty
fast I believe, but for some reason it is not.

Well now I'm going to try to find the culprit. For start of course I'll set
er.extensions.ERXAdaptorChannelDelegate.trace to find if the database itself is
that slow (shouldn't be, but who knows)...

Thanks again and all the best!
OC

> On 15. 7. 2025, at 7:44, Stefan Gärtner <email@hidden> wrote:
>
> 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 <email@hidden>
> Antworten an: OCsite <email@hidden>
> Datum: Dienstag, 15. Juli 2025 um 03:35
> An: ocs--- via Webobjects-dev <email@hidden>
> 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      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >most efficient way to fetch GIDs? (From: OCsite via Webobjects-dev <email@hidden>)
 >Re: most efficient way to fetch GIDs? (From: Stefan Gärtner via Webobjects-dev <email@hidden>)

  • Prev by Date: Re: most efficient way to fetch GIDs?
  • Next by Date: multi-instance best practices?
  • Previous by thread: Re: most efficient way to fetch GIDs?
  • Next by thread: multi-instance best practices?
  • Index(es):
    • Date
    • Thread