Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extbase: Choose lazy or eager loading at runtime

I have a domain object Foo that has an 1:n relation to a domain object Bar.

There are two major use cases where I need to get all foo's matching some criterion. In case A, I care about the bars attached to each foo, in case B, I don't. There are quite a lot of bars, so simply always loading the bars is not good for performance of case A. Similarly, not loading the bars eagerly will lead to an n+1 avalanche in case B. So neither tagging the realtion as @Lazy nor not tagging it is the correct choice.

Now, my question: Is it possible to tell the extbase persistence layer at query time whether to be lazy or eager? If yes, how? If no, is there another way in Extbase to avoid the n+1 problem (i.e. load all necessary bars and then hope that caching works when iterating through the foos)?

My last resort, of course, would be to load the foos with lazy loading, load the bars manually in a second query, and then manually set the relation.

Any suggestions?

like image 214
adhominem Avatar asked Mar 05 '12 15:03

adhominem


1 Answers

I've been playing around with Extbase and delving into the internals in the last few months, and the upshot is this: It' impossible.

I suppose that closes this question, though not the way I'ld like.

Actually, even worse: Eager loading is not implemented at all, the @eager tag which according to the documentation sets eager loading for a relation is ignored.

like image 97
adhominem Avatar answered Oct 26 '22 07:10

adhominem