Partial fix Duplicated query on new posts widget

Jake B.

Well-known member
Affected version
2.0.0 RC 2
This exact query is being duplicated 3 times on the new posts widget:

Code:
SELECT `xf_user`.*
FROM `xf_user`

WHERE (`xf_user`.`user_id` = 0)

Interestingly, this only seems to happen if I put new posts widget on forum view it doesn't happen on the index page even though it's the exact same widget:


Screen Shot 2017-11-15 at 10.54.31 AM.webp

Here's the stack trace from this duplicated query as well:

Screen Shot 2017-11-15 at 10.51.31 AM.webp

And here's a screenshot of my forum view:

Screen Shot 2017-11-15 at 10.55.29 AM.webp

I think this only happens for guest posts/threads, haven't been able to replicate it otherwise
 
So I have fixed this particular instance, though the reproduction steps are pretty particular. Specifically, it only happens in the forum where those specific threads are displayed.

The cause is a bit of a (known) quirk in our entity hydration, though it's not something that would be changed at this point in the 2.0 stage. It remains to be seen if the change is needed in a future release as the issue really only manifests with non-existing relations or to-many/non-primary to-one relations. Specifically, the issue is related to trying to hydrate an entity that we have already hydrated but with additional relations eagerly fetched. The additional relations will be hydrated themselves but won't be attached to the "main" entity until use. If the relation exists and is a primary relation, it will be pulled from the entity cache on first use.

In this instance, I've added code to block attempting to fetch the relation if we detect it's impossible. We can do this by detecting if the Entity\Manager::find() call is looking up an entity with ID === 0 and the condition is on an auto-increment column, as a 0 will cause the auto-increment behavior instead.
 
Back
Top Bottom