[Draft][Please review] Make Paginator use simpler queries when there are no sql joins used (#8278) - #11595
[Draft][Please review] Make Paginator use simpler queries when there are no sql joins used (#8278)#11595d-ph wants to merge 10 commits into
Conversation
…octrine#8278) This is work in progress.
…octrine#8278) This is work in progress.
|
Triggering a new build to address 4. , #11596 should fix it. |
…octrine#8278) This is work in progress.
|
Hi, While I wait for some final answers from stof to my (regrettably) wall of text, may I know your initial thoughts on my proposition to rename some instance variables in the Paginator class, please? I explained it in more details in the discussion above, but the bottom line is:
Would you say that you would initially allow for the changes described above to be made to the Paginator by me? Thanks. |
|
Co-authored-by: Christophe Coevoet <stof@notk.org>
…ck-of-sql-joins' into feature/paginator-auto-detect-lack-of-sql-joins
…octrine#8278) This is work in progress.
…octrine#8278) This is work in progress.
…octrine#8278) This is work in progress.
|
Hi all, I pushed another iteration of this PR, taking into account the feedback so far. Could you re-evaluate, please? Major points:
Thank you. |
| public function __construct( | ||
| Query|QueryBuilder $query, | ||
| private readonly bool $fetchJoinCollection = true, | ||
| private readonly bool $queryCouldProduceDuplicates = true, |
There was a problem hiding this comment.
The docs need to be updated at the very least because of this. Can you also read it and see if anything else needs to be modified, and whether any new behavior you are adding is worth documenting?
| try { | ||
| $rootClassMetadata = $entityManager->getClassMetadata($fromRoot->rangeVariableDeclaration->abstractSchemaName); | ||
| $queryFeatures['rootEntityHasSingleIdentifierFieldName'] = (bool) $rootClassMetadata->getSingleIdentifierFieldName(); | ||
| } catch (MappingException) { |
There was a problem hiding this comment.
You mean the catching of the MappingException?
It's primarily needed because this is how ClassMetadata::getSingleIdentifierFieldName() communicates that "the identifier is not single column". One way to avoid the try..catch is to duplicate the if-conditions from ClassMetadata::getSingleIdentifierFieldName() in here, but having a code duplication here would introduce a maintenance cost, which I personally consider a bigger nuisance than having a try..catch block.
Also, EntityManager::getClassMetadata() throws that exception class when the $className is unrecognised. Instead of making an assumption that "there must be metadata for every class detected at this point of the code", I wanted to be more graceful and defensive, and chose to just catch the exception and assume that the "auto-detection" cannot be carried out.
There was a problem hiding this comment.
We usually avoid using exception for flow control, and I think that's because they are costly.
I think I would add a dedicated method, so as to remove the need of casting the result to a boolean as well, even if it means a little duplication.
Also, EntityManager::getClassMetadata() throws that exception class when the $className is unrecognised. Instead of making an assumption that "there must be metadata for every class detected at this point of the code", I wanted to be more graceful and defensive, and chose to just catch the exception and assume that the "auto-detection" cannot be carried out.
In what case will $className not be recognized and we wouldn't want to let the user know about that?
There was a problem hiding this comment.
Although I agree that resorting to using exceptions has downsides, I personally consider those downsides less painful than the alternative solutions, one of which in this case being an introduction of a maintenance burden by introducing code duplication (or an awkward "marshalling" of error reasons).
Note that even the mentioned article says that mere usage of try..catch (without actually expecting for the "catch path" to be routinely triggered) is negligible.
I'm not going to argue here and will introduce the code duplication (i.e. I will create a ClassMetadata::hasSingleIdentifierFieldName()).
In what case will $className not be recognized and we wouldn't want to let the user know about that?
I can't think of any "normal" case when it would be unrecognised here. So in this regard, I agree that it's better to let the user know that something strange happened.
|
|
||
| /** | ||
| * Returns whether the query joins a collection. | ||
| * @deprecated Use ::getQueryCouldProduceDuplicates() instead. |
There was a problem hiding this comment.
The UPGRADE.md needs to document the deprecations.
…octrine#8278) This is work in progress.
|
Hi stof, would you be able to find some time in the coming weeks to see what you think about the new/current content of this PR, please? |
|
Hi stof. I was wondering whether taking a look at the current diff of this PR is still on your radar. I tried to action all the points that you raised (and where I couldn't, I hope that the middle ground is acceptable). Would you be able to share your thoughts on the current PR in the coming weeks, please? |
|
There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
|
I will continue this. |
|
@d-ph do you intent to resume that work ? |
|
Oups! Sorry for this! |
|
Hi, yes, it's still in my plans. Thanks for clarifying why the PR got closed. Just to manage expectations (if there are any): as everyone, I struggle for time. I do hope to progress this PR within 3 months. Also, my last comment in this PR was a request to re-review it, @stof. I don't immediately remember what there still is to review, however it'd be worthwhile to hear whether you are generally ok with the scope of change in this PR. If I recall correctly, my plan a year ago was to get your "approval" (at least in principle), and then to finish the docs and cleanup, and finally request one last review. Thanks. |
May I ask for an initial review of the code in this PR before I move forward with it, please?
This PR implements the scope of work discussed in #8278 (comment). It only implements the "no joins used" case. It doesn't implement the "only ToOne joins used" case. I plan do implement that other case in a future PR, after this one gets reviewed and hopefully merged.
A few comments:
$fetchJoinCollection = null). This means that there could be a long period of time before the "auto-detection of better defaults" gets enabled by default (if ever).Thank you.